From a6b5339980c592528a9ceb7dca0689b98ae589b3 Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Fri, 24 Dec 2021 18:49:26 +0000 Subject: [PATCH] [K/N] Fix a race in ThreadWithContextTest Merge-request: KT-MR-5349 Merged-by: Alexander Shabalin --- .../runtime/src/main/cpp/SingleThreadExecutorTest.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kotlin-native/runtime/src/main/cpp/SingleThreadExecutorTest.cpp b/kotlin-native/runtime/src/main/cpp/SingleThreadExecutorTest.cpp index 07fc91e4114..0363c1b28ce 100644 --- a/kotlin-native/runtime/src/main/cpp/SingleThreadExecutorTest.cpp +++ b/kotlin-native/runtime/src/main/cpp/SingleThreadExecutorTest.cpp @@ -64,7 +64,6 @@ TEST(ThreadWithContextTest, ContextThreadBound) { EXPECT_CALL(function, Call()).WillOnce([&] { EXPECT_THAT(std::this_thread::get_id(), createdThread); }); auto thread = ::make_unique>([] { return PinnedContext(); }, function.AsStdFunction()); thread->waitInitialized(); - testing::Mock::VerifyAndClearExpectations(&function); testing::Mock::VerifyAndClearExpectations(&mocks.ctorMock); EXPECT_THAT(createdThread, thread->get_id()); EXPECT_THAT(thread->context(), testing::Ref(*createdContext)); @@ -73,6 +72,8 @@ TEST(ThreadWithContextTest, ContextThreadBound) { EXPECT_THAT(std::this_thread::get_id(), createdThread); }); thread.reset(); + // The function is expected to be called at some point between `waitInitialized` and the thread exit. + testing::Mock::VerifyAndClearExpectations(&function); testing::Mock::VerifyAndClearExpectations(&mocks.dtorMock); }