Skip to content

Commit

Permalink
Fix condvar wait for macos
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Jan 15, 2025
1 parent 8281c14 commit b84e49c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tests/z_api_matching_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ static void _context_drop(context_t* c) {
static void _context_wait(context_t* c, context_state_t state, int timeout_s) {
z_mutex_lock(z_mutex_loan_mut(&c->m));
if (c->state != state) {
printf("Waiting for state %d...\n", state);
#ifdef ZENOH_MACOS
_ZP_UNUSED(timeout_s);
z_condvar_wait(z_condvar_loan_mut(&c->cv), z_mutex_loan_mut(&c->m));
#else
z_clock_t clock = z_clock_now();
z_clock_advance_s(&clock, timeout_s);
printf("Waiting for state %d...\n", state);
z_result_t res = z_condvar_wait_until(z_condvar_loan_mut(&c->cv), z_mutex_loan_mut(&c->m), &clock);
if (res == Z_ETIMEDOUT) {
fprintf(stderr, "Timeout waiting for state %d\n", state);
assert(false);
}
#endif
if (c->state != state) {
fprintf(stderr, "Expected state %d, got %d\n", state, c->state);
assert(false);
Expand Down Expand Up @@ -142,15 +147,15 @@ void test_matching_sub(bool background) {
assert_ok(z_declare_subscriber(z_session_loan(&s2), &sub, z_view_keyexpr_loan(&k_sub),
z_closure_sample_move(&callback), NULL));

_context_wait(&context, MATCH, 30);
_context_wait(&context, MATCH, 10);

z_subscriber_drop(z_subscriber_move(&sub));

_context_wait(&context, UNMATCH, 30);
_context_wait(&context, UNMATCH, 10);

z_publisher_drop(z_publisher_move(&pub));

_context_wait(&context, DROP, 30);
_context_wait(&context, DROP, 10);

if (!background) {
z_matching_listener_drop(z_matching_listener_move(&matching_listener));
Expand Down

0 comments on commit b84e49c

Please sign in to comment.