Skip to content

Commit

Permalink
test: libflux: cover queued result futures in async mode
Browse files Browse the repository at this point in the history
Ensure a case where a multiple-result future is use first
synchronously then asynchronously is covered in the unit tests.
  • Loading branch information
grondo committed Nov 16, 2018
1 parent 393af0c commit a63fe70
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/common/libflux/test/future.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,49 @@ void test_multiple_fulfill (void)
flux_reactor_destroy (r);
}

void multiple_fulfill_continuation (flux_future_t *f, void *arg)
{
const void **resultp = arg;
ok (flux_future_get (f, resultp) == 0,
"flux_future_get() in async continuation works");
flux_future_reset (f);
}

void test_multiple_fulfill_asynchronous (void)
{
int rc;
flux_reactor_t *r;
flux_future_t *f;
const void *result;

if (!(r = flux_reactor_create (0)))
BAIL_OUT ("flux_reactor_create failed");

if (!(f = flux_future_create (NULL, NULL)))
BAIL_OUT ("flux_future_create failed");
flux_future_set_reactor (f, r);

flux_future_fulfill (f, "foo", NULL);
flux_future_fulfill (f, "bar", NULL);

/* Call continuation once to get first value and reset future */
multiple_fulfill_continuation (f, &result);

ok (strcmp (result, "foo") == 0,
"calling multiple_fulfill_continuation synchronously worked");

rc = flux_future_then (f, -1., multiple_fulfill_continuation, &result);
cmp_ok (rc, "==", 0,
"flux_future_then() works for multiple fulfilled future");
if (flux_reactor_run (r, FLUX_REACTOR_NOWAIT) < 0)
BAIL_OUT ("flux_reactor_run NOWAIT failed");
ok (strcmp (result, "bar") == 0,
"continuation was called for multiple-fulfilled future");

flux_future_destroy (f);
flux_reactor_destroy (r);
}

int main (int argc, char *argv[])
{
plan (NO_PLAN);
Expand All @@ -954,6 +997,7 @@ int main (int argc, char *argv[])
test_error_string ();

test_multiple_fulfill ();
test_multiple_fulfill_asynchronous ();

done_testing();
return (0);
Expand Down

0 comments on commit a63fe70

Please sign in to comment.