flux_t *connector_init (const char *path, int flags) { ctx_t *c = malloc (sizeof (*c)); if (!c) { errno = ENOMEM; goto error; } memset (c, 0, sizeof (*c)); c->magic = CTX_MAGIC; if (!(c->queue = msglist_create ((msglist_free_f)flux_msg_destroy))) goto error; if (!(c->h = flux_handle_create (c, &handle_ops, flags))) goto error; /* Fake out size, rank, tbon-arity attributes for testing. */ if (flux_attr_fake (c->h, "rank", "0", FLUX_ATTRFLAG_IMMUTABLE) < 0 || flux_attr_fake (c->h, "size", "1", FLUX_ATTRFLAG_IMMUTABLE) < 0 || flux_attr_fake (c->h, "tbon-arity", "2", FLUX_ATTRFLAG_IMMUTABLE) < 0) goto error; return c->h; error: if (c) { int saved_errno = errno; op_fini (c); errno = saved_errno; } return NULL; }
static void *module_thread (void *arg) { module_t *p = arg; assert (p->magic == MODULE_MAGIC); sigset_t signal_set; int errnum; char *uri = xasprintf ("shmem://%s", zuuid_str (p->uuid)); char **av = NULL; char *rankstr = NULL; int ac; assert (p->zctx); /* Connect to broker socket, enable logging, register built-in services */ if (!(p->h = flux_open (uri, 0))) err_exit ("flux_open %s", uri); if (flux_opt_set (p->h, FLUX_OPT_ZEROMQ_CONTEXT, p->zctx, sizeof (p->zctx)) < 0) err_exit ("flux_opt_set ZEROMQ_CONTEXT"); rankstr = xasprintf ("%u", p->rank); if (flux_attr_fake (p->h, "rank", rankstr, FLUX_ATTRFLAG_IMMUTABLE) < 0) { err ("%s: error faking rank attribute", p->name); goto done; } flux_log_set_facility (p->h, p->name); modservice_register (p->h, p); /* Block all signals */ if (sigfillset (&signal_set) < 0) err_exit ("%s: sigfillset", p->name); if ((errnum = pthread_sigmask (SIG_BLOCK, &signal_set, NULL)) != 0) errn_exit (errnum, "pthread_sigmask"); /* Run the module's main(). */ ac = argz_count (p->argz, p->argz_len); av = xzmalloc (sizeof (av[0]) * (ac + 1)); argz_extract (p->argz, p->argz_len, av); if (p->main(p->h, ac, av) < 0) { err ("%s: mod_main returned error", p->name); goto done; } done: if (rankstr) free (rankstr); if (av) free (av); flux_close (p->h); p->h = NULL; return NULL; }
int rpctest_begin_cb (flux_t h, int type, zmsg_t **zmsg, void *arg) { uint32_t nodeid; int i, errors; int old_count; flux_rpc_t *r; const char *json_str; errno = 0; ok (!(r = flux_rpc_multi (h, NULL, "foo", "all", 0)) && errno == EINVAL, "flux_rpc_multi [0] with NULL topic fails with EINVAL"); errno = 0; ok (!(r = flux_rpc_multi (h, "bar", "foo", NULL, 0)) && errno == EINVAL, "flux_rpc_multi [0] with NULL nodeset fails with EINVAL"); errno = 0; ok (!(r = flux_rpc_multi (h, "bar", "foo", "xyz", 0)) && errno == EINVAL, "flux_rpc_multi [0] with bad nodeset fails with EINVAL"); /* working no-payload RPC */ old_count = hello_count; ok ((r = flux_rpc_multi (h, "rpctest.hello", NULL, "all", 0)) != NULL, "flux_rpc_multi [0] with no payload when none is expected works"); if (!r) BAIL_OUT ("can't continue without successful rpc call"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); ok (flux_rpc_get (r, NULL, NULL) == 0, "flux_rpc_get works"); ok (hello_count == old_count + 1, "rpc was called once"); flux_rpc_destroy (r); /* cause remote EPROTO (unexpected payload) - picked up in _get() */ ok ((r = flux_rpc_multi (h, "rpctest.hello", "foo", "all", 0)) != NULL, "flux_rpc_multi [0] with unexpected payload works, at first"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errno = 0; ok (flux_rpc_get (r, NULL, NULL) < 0 && errno == EPROTO, "flux_rpc_get fails with EPROTO"); flux_rpc_destroy (r); /* fake that we have a larger session */ fake_size = 128; char s[16]; uint32_t size = 0; snprintf (s, sizeof (s), "%u", fake_size); flux_attr_fake (h, "size", s, FLUX_ATTRFLAG_IMMUTABLE); flux_get_size (h, &size); cmp_ok (size, "==", fake_size, "successfully faked flux_get_size() of %d", fake_size); /* repeat working no-payload RPC test (now with 128 nodes) */ old_count = hello_count; ok ((r = flux_rpc_multi (h, "rpctest.hello", NULL, "all", 0)) != NULL, "flux_rpc_multi [0-%d] with no payload when none is expected works", fake_size - 1); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errors = 0; for (i = 0; i < fake_size; i++) if (flux_rpc_get (r, NULL, NULL) < 0) errors++; ok (errors == 0, "flux_rpc_get succeded %d times", fake_size); cmp_ok (hello_count - old_count, "==", fake_size, "rpc was called %d times", fake_size); flux_rpc_destroy (r); /* same with a subset */ old_count = hello_count; ok ((r = flux_rpc_multi (h, "rpctest.hello", NULL, "[0-63]", 0)) != NULL, "flux_rpc_multi [0-%d] with no payload when none is expected works", 64 - 1); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errors = 0; for (i = 0; i < 64; i++) if (flux_rpc_get (r, &nodeid, NULL) < 0 || nodeid != i) errors++; ok (errors == 0, "flux_rpc_get succeded %d times, with correct nodeid map", 64); cmp_ok (hello_count - old_count, "==", 64, "rpc was called %d times", 64); flux_rpc_destroy (r); /* same with echo payload */ ok ((r = flux_rpc_multi (h, "rpctest.echo", "foo", "[0-63]", 0)) != NULL, "flux_rpc_multi [0-%d] ok", 64 - 1); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errors = 0; for (i = 0; i < 64; i++) { if (flux_rpc_get (r, NULL, &json_str) < 0 || !json_str || strcmp (json_str, "foo") != 0) errors++; } ok (errors == 0, "flux_rpc_get succeded %d times, with correct return payload", 64); flux_rpc_destroy (r); /* detect partial failure without mresponse */ nodeid_fake_error = 20; ok ((r = flux_rpc_multi (h, "rpctest.nodeid", NULL, "[0-63]", 0)) != NULL, "flux_rpc_multi [0-%d] ok", 64 - 1); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); for (i = 0; i < 64; i++) { if (flux_rpc_get (r, &nodeid, &json_str) < 0) break; } ok (i == 20 && errno == EPERM, "flux_rpc_get correctly reports single error"); flux_rpc_destroy (r); /* test _then (still at fake session size of 128) */ ok ((then_r = flux_rpc_multi (h, "rpctest.hello", NULL, "[0-127]", 0)) != NULL, "flux_rpc_multi [0-127] ok"); ok (flux_rpc_then (then_r, then_cb, h) == 0, "flux_rpc_then works"); /* then_cb stops reactor; results reported, then_r destroyed in main() */ return 0; }