Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ jobs:
uses: timblechmann/nova_github_actions/.github/workflows/cmake-ci.yml@main
with:
cmake_args: -DNOVA_SYNC_TESTS_STRESS_TEST=OFF
enable_sanitizers: true
2 changes: 1 addition & 1 deletion include/nova/sync/event/parking_manual_reset_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class parking_manual_reset_event
bool success = detail::run_with_exponential_backoff_until( [ this ]() -> detail::backoff_result {
if ( state_.load( std::memory_order_acquire ) != 0u )
return detail::backoff_result::success;
return detail::backoff_result::retry_without_backoff;
return detail::backoff_result::retry;
} );
if ( success )
return;
Expand Down
10 changes: 5 additions & 5 deletions test/event_async_asio_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,12 @@ TEMPLATE_TEST_CASE( "async_event stress: signal races async_wait",
using Evt = TestType;
asio_event_runner runner;

const int rounds = 50;
auto completions = std::make_shared< std::atomic< int > >( 0 );
constexpr int rounds = 50;
std::array< Evt, rounds > events;

for ( int i = 0; i < rounds; ++i ) {
Evt evt;
auto completions = std::make_shared< std::atomic< int > >( 0 );

for ( Evt& evt : events ) {
nova::sync::async_wait( runner.ioc, evt, [ completions ]( auto result ) {
REQUIRE( result.has_value() );
++( *completions );
Expand All @@ -300,7 +300,7 @@ TEMPLATE_TEST_CASE( "async_event stress: signal races async_wait",
evt.signal();

// Small sleep to let this round settle before moving to the next
std::this_thread::sleep_for( 2ms );
std::this_thread::sleep_for( 1ms );
}

auto deadline = std::chrono::steady_clock::now() + 5s;
Expand Down
14 changes: 8 additions & 6 deletions test/event_async_qt_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,18 @@ TEMPLATE_TEST_CASE( "async_event (qt): fires after signal from another thread",
REQUIRE( !fired->load() );

// Signal from a background thread
std::thread( [ &evt, signal_sent ] {
std::this_thread::sleep_for( 10ms );
std::thread signal_thread( [ &evt, signal_sent ] {
std::this_thread::sleep_for( 100ms );
*signal_sent = true;
evt.signal();
} ).detach();
} );

process_events_until( std::chrono::steady_clock::now() + 2s, [ &fired ] {
return fired->load();
} );
REQUIRE( fired->load() );
REQUIRE( fired_after_signal->load() );
signal_thread.join();
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -173,17 +174,18 @@ TEMPLATE_TEST_CASE( "async_event (qt): future-based qt_async_wait", "[async_even
auto fut = nova::sync::qt_async_wait( evt, QCoreApplication::instance() );

// Signal from a thread to avoid blocking processEvents indefinitely
std::thread( [ &evt ] {
std::this_thread::sleep_for( 10ms );
std::thread signal( [ &evt ] {
std::this_thread::sleep_for( 100ms );
evt.signal();
} ).detach();
} );

// Drive event loop until future is ready
process_events_until( std::chrono::steady_clock::now() + 2s, [ &fut ] {
return fut.wait_for( 0s ) == std::future_status::ready;
} );

REQUIRE( fut.wait_for( 0s ) == std::future_status::ready );
signal.join();
}

// ---------------------------------------------------------------------------
Expand Down
Loading