Skip to content

Commit

Permalink
libtestutil: drop loopback_create()
Browse files Browse the repository at this point in the history
Problem: the libtestutil loopback_create() function duplicates
loop:// for unit tests that could not rely on loop.so being built,
but now that loop:// is built in, it is no longer required.

Convert unit tests to use the real loop:// connector and remove
the duplicate implementation.
  • Loading branch information
garlick committed Oct 5, 2023
1 parent 9eea0bf commit db53159
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 235 deletions.
5 changes: 2 additions & 3 deletions src/broker/test/overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "src/common/libzmqutil/sockopt.h"
#include "src/common/libzmqutil/cert.h"
#include "src/common/libczmqcontainers/czmq_containers.h"
#include "src/common/libtestutil/util.h"
#include "src/common/libutil/stdlog.h"
#include "src/common/libutil/unlink_recursive.h"
#include "ccan/str/str.h"
Expand Down Expand Up @@ -709,8 +708,8 @@ int main (int argc, char *argv[])

if (!(logs = zlist_new ()))
BAIL_OUT ("zlist_new failed");
if (!(h = loopback_create (0)))
BAIL_OUT ("loopback_create failed");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("could not create loop handle");
if (flux_attr_set_cacheonly (h, "rank", "0") < 0)
BAIL_OUT ("flux_attr_set_cacheonly rank failed");
if (flux_attr_set_cacheonly (h, "hostlist", "test") < 0)
Expand Down
5 changes: 2 additions & 3 deletions src/broker/test/runat.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "src/common/libtap/tap.h"
#include "src/common/libczmqcontainers/czmq_containers.h"
#include "src/common/libtestutil/util.h"
#include "src/common/libutil/stdlog.h"

#include "src/broker/runat.h"
Expand Down Expand Up @@ -361,8 +360,8 @@ int main (int argc, char *argv[])
BAIL_OUT ("zlist_new failed");
if (!(r = flux_reactor_create (FLUX_REACTOR_SIGCHLD)))
BAIL_OUT ("flux_reactor_create failed");
if (!(h = loopback_create (0)))
BAIL_OUT ("loopback_create failed");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("could not create loop handle");
if (flux_set_reactor (h, r) < 0)
BAIL_OUT ("flux_set_reactor failed");
if (flux_attr_set_cacheonly (h, "rank", "0") < 0)
Expand Down
5 changes: 2 additions & 3 deletions src/common/libflux/test/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "src/common/libflux/conf_private.h"

#include "src/common/libtap/tap.h"
#include "src/common/libtestutil/util.h"
#include "ccan/str/str.h"

const char *t1 = \
Expand Down Expand Up @@ -351,8 +350,8 @@ void test_in_handle (void)

/* create test handle
*/
if (!(h = loopback_create (0)))
BAIL_OUT ("loopback_create failed");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("failed to create loop handle");

/* create test config
*/
Expand Down
5 changes: 2 additions & 3 deletions src/common/libflux/test/disconnect.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <flux/core.h>

#include "src/common/libtap/tap.h"
#include "src/common/libtestutil/util.h"

flux_msg_t *create_request (int sender,
uint32_t rolemask,
Expand Down Expand Up @@ -142,8 +141,8 @@ void check_cancel (void)
int count;
uint32_t matchtag;

if (!(h = loopback_create (0)))
BAIL_OUT ("could not create loopback handle");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("failed to create loop handle");

/* populate list of requests with unique senders
*/
Expand Down
5 changes: 2 additions & 3 deletions src/common/libflux/test/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "src/common/libutil/xzmalloc.h"
#include "src/common/libtap/tap.h"
#include "src/common/libtestutil/util.h"

int cb2_called;
void cb2 (flux_t *h, flux_msg_handler_t *mh, const flux_msg_t *msg, void *arg)
Expand Down Expand Up @@ -524,8 +523,8 @@ int main (int argc, char *argv[])

plan (NO_PLAN);

if (!(h = loopback_create (0)))
BAIL_OUT ("can't continue without loopback handle");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("can't continue without loop handle");
ok ((r = flux_get_reactor (h)) != NULL,
"handle created reactor on demand");

Expand Down
8 changes: 4 additions & 4 deletions src/common/libflux/test/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ void test_subscribe_badparams (void)
{
flux_t *h;

if (!(h = loopback_create (0)))
BAIL_OUT ("loopback_create failed");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("could not create loop handle");

errno = 0;
ok (flux_event_subscribe_ex (NULL, "foo", 0) == NULL && errno == EINVAL,
Expand Down Expand Up @@ -288,8 +288,8 @@ void test_subscribe_nosub (void)
{
flux_t *h;

if (!(h = loopback_create (FLUX_O_TEST_NOSUB)))
BAIL_OUT ("loopback_create failed");
if (!(h = flux_open ("loop://", FLUX_O_TEST_NOSUB)))
BAIL_OUT ("could not create loop handle");

ok (flux_event_subscribe (h, "foo") == 0,
"flux_event_subscribe succeeds in loopback with TEST_NOSUB flag");
Expand Down
11 changes: 5 additions & 6 deletions src/common/libflux/test/future.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "src/common/libczmqcontainers/czmq_containers.h"
#include "src/common/libutil/xzmalloc.h"
#include "src/common/libtestutil/util.h"
#include "src/common/libtap/tap.h"
#include "ccan/str/str.h"

Expand Down Expand Up @@ -1366,8 +1365,8 @@ void test_rpc_like_thing_async (bool reverse_destroy_order)
struct thing *t;
flux_reactor_t *r;

if (!(h = loopback_create (0)))
BAIL_OUT ("could not create loopback handle");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("could not create loop handle");
if (!(r = flux_get_reactor (h)))
BAIL_OUT ("flux_get_reactor failed");

Expand Down Expand Up @@ -1412,8 +1411,8 @@ void test_rpc_like_thing (bool reverse_destroy_order)
flux_msg_t *msg;
struct thing *t;

if (!(h = loopback_create (0)))
BAIL_OUT ("could not create loopback handle");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("could not create loop handle");

t = thing_create (h);

Expand Down Expand Up @@ -1445,7 +1444,7 @@ void test_rpc_like_thing_unfulfilled (bool reverse_destroy_order)
flux_t *h;
struct thing *t;

if (!(h = loopback_create (0)))
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("could not create loopback handle");

t = thing_create (h);
Expand Down
5 changes: 2 additions & 3 deletions src/common/libflux/test/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "src/common/libutil/xzmalloc.h"
#include "src/common/libtap/tap.h"
#include "src/common/libtestutil/util.h"
#include "ccan/str/str.h"

/* Destructor for malloc'ed string.
Expand Down Expand Up @@ -98,8 +97,8 @@ int main (int argc, char *argv[])

plan (NO_PLAN);

if (!(h = loopback_create (0)))
BAIL_OUT ("can't continue without loopback handle");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("can't continue without loop handle");

test_handle_invalid_args (h);

Expand Down
4 changes: 2 additions & 2 deletions src/common/libflux/test/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ void test_set_running (void)
{
flux_t *h;

if (!(h = loopback_create (0)))
BAIL_OUT ("loopback_create failed");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("could not create loop handle");

ok (flux_module_set_running (h) == 0,
"flux_module_set_running returns success");
Expand Down
4 changes: 2 additions & 2 deletions src/common/libflux/test/reactor_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static void leak_msg_handler (void)
flux_t *h;
flux_msg_handler_t *mh;

if (!(h = loopback_create (0)))
if (!(h = flux_open ("loop://", 0)))
exit (1);
if (!(mh = flux_msg_handler_create (h, FLUX_MATCH_ANY, dummy, NULL)))
exit (1);
Expand All @@ -148,7 +148,7 @@ int main (int argc, char *argv[])

plan (NO_PLAN);

if (!(h = loopback_create (0)))
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("can't continue without loop handle");
flux_comms_error_set (h, comms_err, NULL);
ok ((reactor = flux_get_reactor (h)) != NULL,
Expand Down
9 changes: 4 additions & 5 deletions src/common/libflux/test/response.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <flux/core.h>

#include "src/common/libtap/tap.h"
#include "src/common/libtestutil/util.h"
#include "ccan/str/str.h"

int main (int argc, char *argv[])
Expand Down Expand Up @@ -157,9 +156,9 @@ int main (int argc, char *argv[])
flux_msg_destroy (msg);

/* respond with request=NULL */
h = loopback_create (0);
h = flux_open ("loop://", 0);
if (!h)
BAIL_OUT ("loopback_create");
BAIL_OUT ("could not create loop handle");
errno = 0;
ok (flux_respond (h, NULL, NULL) < 0 && errno == EINVAL,
"flux_respond msg=NULL fails with EINVAL");
Expand All @@ -175,9 +174,9 @@ int main (int argc, char *argv[])
flux_close (h);

/* errnum=0 */
h = loopback_create (0);
h = flux_open ("loop://", 0);
if (!h)
BAIL_OUT ("loopback_create");
BAIL_OUT ("could not create loop handle");
msg = flux_request_encode ("foo", NULL);
if (!msg)
BAIL_OUT ("flux_request_encode failed");
Expand Down
5 changes: 2 additions & 3 deletions src/common/libflux/test/rpc_security.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "src/common/libutil/xzmalloc.h"
#include "src/common/libtap/tap.h"
#include "src/common/libtestutil/util.h"

static int cred_get (flux_t *h, struct flux_msg_cred *cr)
{
Expand Down Expand Up @@ -328,8 +327,8 @@ int main (int argc, char *argv[])

plan (NO_PLAN);

if (!(h = loopback_create (0)))
BAIL_OUT ("cannot continue without loopback handle");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("cannot continue without loop handle");
flux_comms_error_set (h, comms_err, NULL);

check_rpc_oneway (h);
Expand Down
9 changes: 4 additions & 5 deletions src/common/libflux/test/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <flux/core.h>

#include "src/common/libtap/tap.h"
#include "src/common/libtestutil/util.h"

void send_fake_heartbeat (flux_t *h, int seq)
{
Expand All @@ -42,8 +41,8 @@ void test_non_reactive_loop (void)
int rc;
int i;

if (!(h = loopback_create (0)))
BAIL_OUT ("could not create loopback handle");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("could not create loop handle");

f = flux_sync_create (h, 0.);
ok (f != NULL,
Expand Down Expand Up @@ -105,15 +104,15 @@ void continuation (flux_future_t *f, void *arg)

void test_sync_reactive (double heartrate, double min, double max)
{
flux_t *h = loopback_create (0);
flux_t *h = flux_open ("loop://", 0);
struct heartbeat_ctx ctx = { .h = h, .seq = 0 };
flux_reactor_t *r;
flux_watcher_t *timer;
flux_future_t *f;
int count;

if (!h)
BAIL_OUT ("could not create loopback handle");
BAIL_OUT ("could not create loop handle");
if (!(r = flux_get_reactor (h)))
BAIL_OUT ("flux_get_reactor failed on loopback handle");

Expand Down
13 changes: 6 additions & 7 deletions src/common/libsdexec/test/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "ccan/array_size/array_size.h"
#include "src/common/libtap/tap.h"
#include "src/common/libtestutil/util.h"
#include "src/common/libioencode/ioencode.h"
#include "channel.h"

Expand Down Expand Up @@ -58,8 +57,8 @@ void test_input (void)
json_t *io;
json_t *io_eof;

if (!(h = loopback_create (0)))
BAIL_OUT ("could not create loopback flux_t handle for testing");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("could not create loop flux_t handle for testing");
if (flux_attr_set_cacheonly (h, "rank", "0") < 0)
BAIL_OUT ("could not set rank for testing");
ch = sdexec_channel_create_input (h, "in");
Expand Down Expand Up @@ -148,8 +147,8 @@ void test_output (void)
struct channel *ch;
int fd;

if (!(h = loopback_create (0)))
BAIL_OUT ("could not create loopback flux_t handle for testing");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("could not create loop flux_t handle for testing");
if (flux_attr_set_cacheonly (h, "rank", "0") < 0)
BAIL_OUT ("could not set rank for testing");
ch = sdexec_channel_create_output (h, "out", output_cb, error_cb, NULL);
Expand Down Expand Up @@ -200,8 +199,8 @@ void test_inval (void)
flux_t *h;
json_t *io;

if (!(h = loopback_create (0)))
BAIL_OUT ("could not create loopback flux_t handle for testing");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("could not create loop flux_t handle for testing");
if (!(io = ioencode ("foo", "0", NULL, 0, true)))
BAIL_OUT ("could not create json io object");

Expand Down
5 changes: 2 additions & 3 deletions src/common/libsdexec/test/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <flux/core.h>

#include "src/common/libtap/tap.h"
#include "src/common/libtestutil/util.h"
#include "list.h"

void test_inval (void)
Expand All @@ -26,8 +25,8 @@ void test_inval (void)
struct unit_info info;
flux_future_t *f;

if (!(h = loopback_create (0)))
BAIL_OUT ("could not create loopback flux_t handle for testing");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("could not create loop flux_t handle for testing");
if (!(f = flux_future_create (NULL, 0)))
BAIL_OUT ("could not create future for testing");

Expand Down
5 changes: 2 additions & 3 deletions src/common/libsdexec/test/property.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <flux/core.h>

#include "src/common/libtap/tap.h"
#include "src/common/libtestutil/util.h"
#include "property.h"

void test_dict (void)
Expand Down Expand Up @@ -45,8 +44,8 @@ void test_inval (void)
flux_future_t *f;
json_t *dict;

if (!(h = loopback_create (0)))
BAIL_OUT ("could not create loopback flux_t handle for testing");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("could not create loop flux_t handle for testing");
if (!(f = flux_future_create (NULL, 0)))
BAIL_OUT ("could not create future for testing");
if (!(dict = json_pack ("{s:[si]}", "foo", "i", 42)))
Expand Down
5 changes: 2 additions & 3 deletions src/common/libsdexec/test/start.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "src/common/libsubprocess/command.h"
#include "src/common/libtap/tap.h"
#include "src/common/libtestutil/util.h"
#include "src/common/libutil/jpath.h"
#include "start.h"

Expand All @@ -35,8 +34,8 @@ void test_inval (void)
json_t *o;
flux_error_t error;

if (!(h = loopback_create (0)))
BAIL_OUT ("could not create loopback flux_t handle for testing");
if (!(h = flux_open ("loop://", 0)))
BAIL_OUT ("could not create loop flux_t handle for testing");
if (!(f = flux_future_create (NULL, 0)))
BAIL_OUT ("could not create future for testing");
if (!(cmd = flux_cmd_create (ac, av, environ))
Expand Down
Loading

0 comments on commit db53159

Please sign in to comment.