int main (int argc, char *argv[]) { flux_t h; flux_reactor_t *reactor; plan (4+11+3+4+3+5+2); (void)setenv ("FLUX_CONNECTOR_PATH", CONNECTOR_PATH, 0); ok ((h = flux_open ("loop://", 0)) != NULL, "opened loop connector"); if (!h) BAIL_OUT ("can't continue without loop handle"); flux_fatal_set (h, fatal_err, NULL); ok ((reactor = flux_get_reactor (h)) != NULL, "obtained reactor"); if (!reactor) BAIL_OUT ("can't continue without reactor"); ok (flux_reactor_run (reactor, 0) == 0, "general: reactor ran to completion (no watchers)"); errno = 0; ok (flux_sleep_on (h, FLUX_MATCH_ANY) < 0 && errno == EINVAL, "general: flux_sleep_on outside coproc fails with EINVAL"); test_timer (reactor); // 11 test_fd (reactor); // 3 test_zmq (reactor); // 4 test_msg (h); // 3 test_multmatch (h); // 5 /* Misc */ lives_ok ({ reactor_destroy_early ();}, "destroying reactor then watcher doesn't segfault");
int main (int argc, char **argv) { flux_t h; heartbeat_t *hb; flux_msg_handler_t *w; plan (18); check_codec (); (void)setenv ("FLUX_CONNECTOR_PATH", CONNECTOR_PATH, 0); ok ((h = flux_open ("loop://", 0)) != NULL, "opened loop connector"); if (!h) BAIL_OUT ("can't continue without loop handle"); flux_fatal_set (h, fatal_err, NULL); ok ((hb = heartbeat_create ()) != NULL, "heartbeat_create works"); heartbeat_set_flux (hb, h); ok (heartbeat_get_rate (hb) == 2., "heartbeat_get_rate returns default of 2s"); errno = 0; ok (heartbeat_set_rate (hb, -1) < 1 && errno == EINVAL, "heartbeat_set_rate -1 fails with EINVAL"); errno = 0; ok (heartbeat_set_rate (hb, 1000000) < 1 && errno == EINVAL, "heartbeat_set_rate 1000000 fails with EINVAL"); ok (heartbeat_set_ratestr (hb, "250ms") == 0, "heartbeat_set_ratestr 250ms works"); ok (heartbeat_get_rate (hb) == 0.250, "heartbeat_get_rate returns what was set"); ok (heartbeat_set_rate (hb, 0.1) == 0, "heartbeat_set_rate 0.1 works"); ok (heartbeat_get_rate (hb) == 0.1, "heartbeat_get_rate returns what was set"); ok (heartbeat_get_epoch (hb) == 0, "heartbeat_get_epoch works, default is zero"); w = flux_msg_handler_create (h, FLUX_MATCH_EVENT, heartbeat_event_cb, hb); ok (w != NULL, "created event watcher"); flux_msg_handler_start (w); ok (heartbeat_start (hb) == 0, "heartbeat_start works"); ok (flux_reactor_run (flux_get_reactor (h), 0) == 0, "flux reactor exited normally"); heartbeat_destroy (hb); flux_msg_handler_destroy (w); flux_close (h); done_testing (); return 0; }
int main (int argc, char *argv[]) { flux_msg_t *msg; flux_t h; flux_reactor_t *reactor; plan (35); (void)setenv ("FLUX_CONNECTOR_PATH", CONNECTOR_PATH, 0); ok ((h = flux_open ("loop://", FLUX_O_COPROC)) != NULL, "opened loop connector"); if (!h) BAIL_OUT ("can't continue without loop handle"); ok ((reactor = flux_get_reactor (h)) != NULL, "obtained reactor"); if (!reactor) BAIL_OUT ("can't continue without reactor"); flux_fatal_set (h, fatal_err, NULL); flux_fatal_error (h, __FUNCTION__, "Foo"); ok (fatal_tested == true, "flux_fatal function is called on fatal error"); /* create nodeset for last _then test */ ok ((then_ns = nodeset_create ()) != NULL, "nodeset created ok"); ok (flux_msghandler_addvec (h, htab, htablen, NULL) == 0, "registered message handlers"); /* test continues in rpctest_begin_cb() so that rpc calls * can sleep while we answer them */ ok ((msg = flux_request_encode ("rpctest.begin", NULL)) != NULL && flux_send (h, msg, 0) == 0, "sent message to initiate test"); ok (flux_reactor_run (reactor, 0) == 0, "reactor completed normally"); flux_msg_destroy (msg); /* Check result of last _then test */ ok (nodeset_count (then_ns) == 128, "then callback worked with correct nodemap"); nodeset_destroy (then_ns); flux_rpc_destroy (then_r); flux_close (h); done_testing(); return (0); }
int main (int argc, char *argv[]) { flux_msg_t *msg; flux_t h; plan (33); (void)setenv ("FLUX_CONNECTOR_PATH", CONNECTOR_PATH, 0); ok ((h = flux_open ("loop://", FLUX_O_COPROC)) != NULL, "opened loop connector"); if (!h) BAIL_OUT ("can't continue without loop handle"); flux_fatal_set (h, fatal_err, NULL); ok (flux_msg_watcher_addvec (h, htab, NULL) == 0, "registered message handlers"); /* test continues in rpctest_begin_cb() so that rpc calls * can sleep while we answer them */ ok ((msg = flux_request_encode ("rpctest.begin", NULL)) != NULL, "encoded rpctest.begin request OK"); ok (flux_send (h, msg, 0) == 0, "sent rpctest.begin request"); ok (flux_reactor_start (h) == 0, "reactor completed normally"); flux_msg_destroy (msg); /* test _then: Slightly tricky. * Send request. We're not in a coproc ctx here in main(), so there * will be no response, therefore, check will be false. Register * continuation, start reactor. Response will be received, continuation * will be invoked. Continuation stops the reactor. */ flux_rpc_t *r; ok ((r = flux_rpc (h, "rpctest.echo", "xxx", FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with payload when payload is expected works"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); /* reg/unreg _then a couple times for fun */ ok (flux_rpc_then (r, NULL, 0) == 0, "flux_rpc_then with NULL cb works"); ok (flux_rpc_then (r, then_cb, h) == 0, "flux_rpc_then works after NULL"); ok (flux_rpc_then (r, NULL, 0) == 0, "flux_rpc_then with NULL cb after non-NULL works"); ok (flux_rpc_then (r, then_cb, h) == 0, "flux_rpc_then works"); /* enough of that */ ok (flux_reactor_start (h) == 0, "reactor completed normally"); flux_rpc_destroy (r); /* Test a _then corner case: * If _check() is called before _then(), a message may have been cached * in the flux_rpc_t. rpctest_thenbug_cb creates this condition. * Next, _then continuation is installed, but will reactor call it? * This will hang if rpc implementation doesn't return a cached message * back to the handle in _then(). Else, continuation will stop reactor. */ ok ((thenbug_r = flux_rpc (h, "rpctest.echo", "xxx", FLUX_NODEID_ANY, 0)) != NULL, "thenbug: sent echo request"); do { if (!(msg = flux_request_encode ("rpctest.thenbug", NULL)) || flux_send (h, msg, 0) < 0 || flux_reactor_start (h) < 0) { flux_msg_destroy (msg); break; } flux_msg_destroy (msg); } while (!flux_rpc_check (thenbug_r)); ok (true, "thenbug: check says message ready"); ok (flux_rpc_then (thenbug_r, then_cb, h) == 0, "thenbug: registered then - hangs on failure"); ok (flux_reactor_start (h) == 0, "reactor completed normally"); flux_rpc_destroy (thenbug_r); flux_msg_watcher_delvec (h, htab); flux_close (h); done_testing(); return (0); }