From a63fe70905b9eee009df5e38266c0e752bce3d7c Mon Sep 17 00:00:00 2001 From: "Mark A. Grondona" Date: Fri, 16 Nov 2018 10:32:25 -0800 Subject: [PATCH] test: libflux: cover queued result futures in async mode Ensure a case where a multiple-result future is use first synchronously then asynchronously is covered in the unit tests. --- src/common/libflux/test/future.c | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/common/libflux/test/future.c b/src/common/libflux/test/future.c index 2981bde1166f..54b6cc84e71a 100644 --- a/src/common/libflux/test/future.c +++ b/src/common/libflux/test/future.c @@ -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); @@ -954,6 +997,7 @@ int main (int argc, char *argv[]) test_error_string (); test_multiple_fulfill (); + test_multiple_fulfill_asynchronous (); done_testing(); return (0);