Fixed sporadic in threading tests (#14270)

This commit is contained in:
Ilya Churaev 2022-11-30 08:30:21 +04:00 committed by GitHub
parent 9ba304de72
commit fa0adc87fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,7 +30,23 @@ protected:
std::string modelName = "CoreThreadingTests.xml", weightsName = "CoreThreadingTests.bin";
public:
static std::string generateTestFilePrefix() {
// Generate unique file names based on test name, thread id and timestamp
// This allows execution of tests in parallel (stress mode)
auto testInfo = ::testing::UnitTest::GetInstance()->current_test_info();
std::string testName = testInfo->test_case_name();
testName += testInfo->name();
testName = std::to_string(std::hash<std::string>()(testName));
std::stringstream ss;
auto ts = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now().time_since_epoch());
ss << testName << "_" << std::this_thread::get_id() << "_" << ts.count();
testName = ss.str();
return testName;
}
void SetUp() override {
auto prefix = generateTestFilePrefix();
modelName = prefix + modelName;
weightsName = prefix + weightsName;
FuncTestUtils::TestModel::generateTestModel(modelName, weightsName);
}