From f87b40fca57f0c8a1655eb65d919243087b4db72 Mon Sep 17 00:00:00 2001 From: Luca Guerra Date: Tue, 24 Sep 2024 15:58:38 +0000 Subject: [PATCH] fix(libsinsp-e2e-tests): concurrency Signed-off-by: Luca Guerra --- test/libsinsp_e2e/event_capture.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test/libsinsp_e2e/event_capture.cpp b/test/libsinsp_e2e/event_capture.cpp index 120c5ab9e3..5face207e8 100644 --- a/test/libsinsp_e2e/event_capture.cpp +++ b/test/libsinsp_e2e/event_capture.cpp @@ -107,7 +107,13 @@ void event_capture::capture() { sinsp_evt* event; bool result = true; int32_t next_result = SCAP_SUCCESS; - while(!m_capture_stopped && result && !::testing::Test::HasFatalFailure()) { + while(result && !::testing::Test::HasFatalFailure()) { + { + std::lock_guard lock(m_object_state_mutex); + if(m_capture_stopped) { + break; + } + } { std::scoped_lock inspector_next_lock(m_inspector_mutex); next_result = get_inspector()->next(&event); @@ -120,7 +126,10 @@ void event_capture::capture() { } if(!signaled_start) { signaled_start = true; - m_capture_started = true; + { + std::lock_guard lock(m_object_state_mutex); + m_capture_started = true; + } m_condition_started.notify_one(); } } @@ -171,8 +180,9 @@ void event_capture::capture() { } m_capture_stopped = true; - m_condition_stopped.notify_one(); } // End teardown synchronized section + + m_condition_stopped.notify_one(); } void event_capture::stop_capture() {