diff --git a/tests/tracing/helpers/mock_threads.cc b/tests/tracing/helpers/mock_threads.cc index 0dc96b1..5bca023 100644 --- a/tests/tracing/helpers/mock_threads.cc +++ b/tests/tracing/helpers/mock_threads.cc @@ -1,5 +1,7 @@ #include "mock_threads.h" +#include + #include "utils.h" using namespace std::chrono_literals; @@ -38,6 +40,7 @@ void MockRegularThread::RunOneIteration(std::function& } void MockRegularThread::Run() { + started_ = true; while (!StopRequested()) { { std::unique_lock lock(mutex_); diff --git a/tests/tracing/helpers/mock_threads.h b/tests/tracing/helpers/mock_threads.h index 4256755..fd0b7a9 100644 --- a/tests/tracing/helpers/mock_threads.h +++ b/tests/tracing/helpers/mock_threads.h @@ -14,6 +14,7 @@ extern const char* kCyclicThreadName; class MockRegularThread : public cactus_rt::Thread { static cactus_rt::ThreadConfig MakeConfig(); + std::atomic_bool started_ = false; std::condition_variable cv_; std::mutex mutex_; std::optional> f_ = std::nullopt; @@ -28,6 +29,10 @@ class MockRegularThread : public cactus_rt::Thread { return Tracer(); } + inline bool Started() const noexcept { + return started_; + } + protected: void Run() final; }; diff --git a/tests/tracing/single_threaded_test.cc b/tests/tracing/single_threaded_test.cc index 2134985..c9976b0 100644 --- a/tests/tracing/single_threaded_test.cc +++ b/tests/tracing/single_threaded_test.cc @@ -2,7 +2,9 @@ #include #include +#include #include +#include #include "helpers/assert_helpers.h" #include "helpers/mock_sink.h" @@ -37,6 +39,9 @@ class SingleThreadTracingTest : public ::testing::Test { app_.RegisterThread(regular_thread_); app_.StartTraceSession(sink_); // TODO: make each test manually start the trace session! app_.Start(); + while (!regular_thread_->Started()) { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); // Not that efficient but OK + } } void TearDown() override { @@ -266,9 +271,12 @@ TEST_F(SingleThreadTracingTest, StopTracingAndNoEventsAreRecorded) { auto traces = sink_->LoggedTraces(); auto packets = GetPacketsFromTraces(traces); - ASSERT_EQ(packets.size(), 1); + ASSERT_EQ(packets.size(), 2); AssertIsProcessTrackDescriptor(*packets[0], kAppName); + const auto process_track_uuid = packets[0]->track_descriptor().uuid(); + + AssertIsThreadTrackDescriptor(*packets[1], kRegularThreadName, process_track_uuid); } TEST_F(SingleThreadTracingTest, RestartTracingStartsNewSession) { @@ -310,8 +318,6 @@ TEST_F(SingleThreadTracingTest, RestartTracingStartsNewSession) { AssertIsThreadTrackDescriptor(*packets2[1], kRegularThreadName, process_track_uuid); auto thread_track_uuid = packets2[1]->track_descriptor().uuid(); - std::cout << "packets2: " << packets2[2]->ShortDebugString() << "\n"; - // Event1 is emitted as interned data because that thread is still active and the event name got interned previously. auto event_names = GetInternedEventNames(*packets2[2]); ASSERT_EQ(event_names.size(), 1);