From 4e668fdd5b5da0d46f97d835249dbe5f0ea319a7 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 19 Oct 2017 15:16:25 -0700 Subject: fixes #84 Consider using msec for durations There is now a public nng_duration type. We have also updated the zerotier work to work with the signed int64_t's that the latst ZeroTier dev branch is using. --- tests/bus.c | 16 ++++---- tests/compat_bug777.c | 6 +-- tests/compat_reqrep.c | 10 ++--- tests/compat_testutil.h | 6 +-- tests/device.c | 24 ++++++----- tests/event.c | 7 ++-- tests/pair1.c | 74 +++++++++++++++++---------------- tests/pipeline.c | 27 ++++++------ tests/platform.c | 57 +++++++------------------- tests/pollfd.c | 4 +- tests/pubsub.c | 11 ++--- tests/reconnect.c | 14 +++---- tests/reqrep.c | 16 ++++---- tests/scalability.c | 12 +++--- tests/sock.c | 107 +++++++++++++++++++++++++----------------------- tests/stubs.h | 16 ++++---- tests/survey.c | 13 +++--- tests/synch.c | 36 ++++++++-------- tests/trantest.h | 6 +-- tests/udp.c | 2 +- tests/zt.c | 45 ++++++++++---------- 21 files changed, 244 insertions(+), 265 deletions(-) (limited to 'tests') diff --git a/tests/bus.c b/tests/bus.c index 3cf785d9..dd36d5a5 100644 --- a/tests/bus.c +++ b/tests/bus.c @@ -37,10 +37,10 @@ TestMain("BUS pattern", { }); Convey("We can create a linked BUS topology", { - nng_socket bus1; - nng_socket bus2; - nng_socket bus3; - uint64_t rtimeo; + nng_socket bus1; + nng_socket bus2; + nng_socket bus3; + nng_duration rtimeo; So(nng_bus_open(&bus1) == 0); So(nng_bus_open(&bus2) == 0); @@ -56,10 +56,10 @@ TestMain("BUS pattern", { So(nng_dial(bus2, addr, NULL, 0) == 0); So(nng_dial(bus3, addr, NULL, 0) == 0); - rtimeo = 50000; - So(nng_setopt_usec(bus1, NNG_OPT_RECVTIMEO, rtimeo) == 0); - So(nng_setopt_usec(bus2, NNG_OPT_RECVTIMEO, rtimeo) == 0); - So(nng_setopt_usec(bus3, NNG_OPT_RECVTIMEO, rtimeo) == 0); + rtimeo = 50; + So(nng_setopt_ms(bus1, NNG_OPT_RECVTIMEO, rtimeo) == 0); + So(nng_setopt_ms(bus2, NNG_OPT_RECVTIMEO, rtimeo) == 0); + So(nng_setopt_ms(bus3, NNG_OPT_RECVTIMEO, rtimeo) == 0); Convey("Messages delivered", { nng_msg *msg; diff --git a/tests/compat_bug777.c b/tests/compat_bug777.c index 7bd6fce5..686b8181 100644 --- a/tests/compat_bug777.c +++ b/tests/compat_bug777.c @@ -1,5 +1,6 @@ /* - Copyright 2016 Garrett D'Amore + Copyright 2017 Garrett D'Amore + Copyright 2017 Capitar IT Group BV Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -34,7 +35,7 @@ int main (int argc, const char *argv[]) test_bind (sb, "inproc://pair"); sc1 = test_socket (AF_SP, NN_PAIR); test_connect (sc1, "inproc://pair"); - nng_usleep(100000); + nn_sleep (100); sc2 = test_socket (AF_SP, NN_PAIR); test_connect (sc2, "inproc://pair"); @@ -45,4 +46,3 @@ int main (int argc, const char *argv[]) test_recv (sb, "THERE"); return 0; } - diff --git a/tests/compat_reqrep.c b/tests/compat_reqrep.c index 51ff4fb8..046955cf 100644 --- a/tests/compat_reqrep.c +++ b/tests/compat_reqrep.c @@ -1,5 +1,7 @@ /* Copyright (c) 2012 Martin Sustrik All rights reserved. + Copyright 2017 Garrett D'Amore + Copyright 2017 Capitar IT Group BV Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -26,8 +28,6 @@ #define SOCKET_ADDRESS "inproc://test" -extern void nng_usleep(uint64_t); - int main () { int rc; @@ -75,7 +75,7 @@ int main () rep1 = test_socket (AF_SP, NN_REP); test_connect (rep1, SOCKET_ADDRESS); - nng_usleep(10000); // ensure rep1 binds before rep2 + nn_sleep(10); // ensure rep1 binds before rep2 rep2 = test_socket (AF_SP, NN_REP); test_connect (rep2, SOCKET_ADDRESS); @@ -86,7 +86,7 @@ int main () test_setsockopt (rep2, NN_SOL_SOCKET, NN_RCVTIMEO, &timeo, sizeof (timeo)); // Give time for connections to settle -- required for LB stuff. - nng_usleep(100000); + nn_sleep(100); test_send (req1, "ABC"); test_recv (rep1, "ABC"); @@ -148,7 +148,7 @@ int main () rep1 = test_socket (AF_SP, NN_REP); test_connect (rep1, SOCKET_ADDRESS); rep2 = test_socket (AF_SP, NN_REP); - nng_usleep(10000); // give time for rep1 to connect + nn_sleep (10); // give time for rep1 to connect test_connect (rep2, SOCKET_ADDRESS); timeo = 500; // Was 200, but Windows occasionally fails at that rate. diff --git a/tests/compat_testutil.h b/tests/compat_testutil.h index fd18cbad..00e7cb0b 100644 --- a/tests/compat_testutil.h +++ b/tests/compat_testutil.h @@ -222,10 +222,10 @@ test_addr_from(char *out, const char *proto, const char *ip, int port) } void -nn_sleep(uint64_t msec) +nn_sleep(int32_t msec) { - void nng_usleep(uint64_t); - nng_usleep(msec * 1000); + void nng_msleep(int32_t); + nng_msleep(msec); } struct nn_thread { diff --git a/tests/device.c b/tests/device.c index d1e08449..5c650a91 100644 --- a/tests/device.c +++ b/tests/device.c @@ -31,6 +31,8 @@ dodev(void *arg) nng_device(d->s1, d->s2); } +#define SECOND(x) ((x) *1000) + Main({ Test("PAIRv1 device", { @@ -38,13 +40,13 @@ Main({ const char *addr2 = "inproc://dev2"; Convey("We can create a PAIRv1 device", { - nng_socket dev1; - nng_socket dev2; - nng_socket end1; - nng_socket end2; - uint64_t tmo; - nng_msg * msg; - void * thr; + nng_socket dev1; + nng_socket dev2; + nng_socket end1; + nng_socket end2; + nng_duration tmo; + nng_msg * msg; + void * thr; So(nng_pair1_open(&dev1) == 0); So(nng_pair1_open(&dev2) == 0); @@ -72,11 +74,11 @@ Main({ So(nng_dial(end1, addr1, NULL, 0) == 0); So(nng_dial(end2, addr2, NULL, 0) == 0); - tmo = 1000000; - So(nng_setopt_usec(end1, NNG_OPT_RECVTIMEO, tmo) == 0); - So(nng_setopt_usec(end2, NNG_OPT_RECVTIMEO, tmo) == 0); + tmo = SECOND(1); + So(nng_setopt_ms(end1, NNG_OPT_RECVTIMEO, tmo) == 0); + So(nng_setopt_ms(end2, NNG_OPT_RECVTIMEO, tmo) == 0); - nng_usleep(100000); + nng_msleep(100); Convey("Device can send and receive", { So(nng_msg_alloc(&msg, 0) == 0); diff --git a/tests/event.c b/tests/event.c index 8d7a969f..065b2e16 100644 --- a/tests/event.c +++ b/tests/event.c @@ -1,5 +1,6 @@ // // Copyright 2017 Garrett D'Amore +// Copyright 2017 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -103,7 +104,7 @@ TestMain("Event Handling", { So(nng_dial(sock2, addr, NULL, 0) == 0); // Let everything connect. - nng_usleep(100000); + nng_msleep(100); Convey("We can register callbacks", { So((notify1 = nng_setnotify(sock1, NNG_EV_CAN_SND, @@ -125,7 +126,7 @@ TestMain("Event Handling", { // this. Probably the msgq needs to // toggle on reads. - // nng_usleep(20000); + // nng_msleep(20); // So(nng_recvmsg(sock2, &msg, 0) == // 0); @@ -134,7 +135,7 @@ TestMain("Event Handling", { // nng_msg_free(msg); // The notify runs async... - nng_usleep(100000); + nng_msleep(100); So(evcnt1.writeable == 1); So(evcnt2.readable == 1); diff --git a/tests/pair1.c b/tests/pair1.c index 3789d7c9..9ed73037 100644 --- a/tests/pair1.c +++ b/tests/pair1.c @@ -14,20 +14,23 @@ #include +#define SECOND(x) ((x) *1000) +#define MILLISECOND(x) (x) + #define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s)) #define CHECKSTR(m, s) \ So(nng_msg_len(m) == strlen(s)); \ So(memcmp(nng_msg_body(m), s, strlen(s)) == 0) TestMain("PAIRv1 protocol", { - const char *templ = "inproc://pairv1/%u"; - char addr[NNG_MAXADDRLEN + 1]; - nng_socket s1 = 0; - nng_socket c1 = 0; - nng_socket c2 = 0; - uint64_t tmo; - uint32_t v; - size_t sz; + const char * templ = "inproc://pairv1/%u"; + char addr[NNG_MAXADDRLEN + 1]; + nng_socket s1 = 0; + nng_socket c1 = 0; + nng_socket c2 = 0; + nng_duration tmo; + uint32_t v; + size_t sz; atexit(nng_fini); @@ -43,20 +46,20 @@ TestMain("PAIRv1 protocol", { nng_close(c2); }); - tmo = 300000; - So(nng_setopt_usec(s1, NNG_OPT_RECVTIMEO, tmo) == 0); - So(nng_setopt_usec(c1, NNG_OPT_RECVTIMEO, tmo) == 0); - So(nng_setopt_usec(c2, NNG_OPT_RECVTIMEO, tmo) == 0); + tmo = MILLISECOND(300); + So(nng_setopt_ms(s1, NNG_OPT_RECVTIMEO, tmo) == 0); + So(nng_setopt_ms(c1, NNG_OPT_RECVTIMEO, tmo) == 0); + So(nng_setopt_ms(c2, NNG_OPT_RECVTIMEO, tmo) == 0); tmo = 0; - So(nng_getopt_usec(s1, NNG_OPT_RECVTIMEO, &tmo) == 0); - So(tmo == 300000); + So(nng_getopt_ms(s1, NNG_OPT_RECVTIMEO, &tmo) == 0); + So(tmo == MILLISECOND(300)); Convey("Monogamous cooked mode works", { nng_msg *msg; So(nng_listen(s1, addr, NULL, 0) == 0); So(nng_dial(c1, addr, NULL, 0) == 0); - nng_usleep(20000); + nng_msleep(20); So(nng_msg_alloc(&msg, 0) == 0); APPENDSTR(msg, "ALPHA"); @@ -78,7 +81,7 @@ TestMain("PAIRv1 protocol", { So(nng_listen(s1, addr, NULL, 0) == 0); So(nng_dial(c1, addr, NULL, 0) == 0); - nng_usleep(100000); + nng_msleep(100); So(nng_dial(c2, addr, NULL, 0) == 0); So(nng_msg_alloc(&msg, 0) == 0); @@ -97,28 +100,28 @@ TestMain("PAIRv1 protocol", { Convey("Cannot set raw mode after connect", { So(nng_listen(s1, addr, NULL, 0) == 0); So(nng_dial(c1, addr, NULL, 0) == 0); - nng_usleep(100000); + nng_msleep(100); So(nng_setopt_int(s1, NNG_OPT_RAW, 1) == NNG_ESTATE); So(nng_setopt_int(c1, NNG_OPT_RAW, 1) == NNG_ESTATE); }); Convey("Polyamorous mode is best effort", { - int rv; - int i; - nng_msg *msg; + int rv; + int i; + nng_msg * msg; + nng_duration to = MILLISECOND(100); So(nng_setopt_int(s1, NNG_OPT_PAIR1_POLY, 1) == 0); So(nng_setopt_int(s1, NNG_OPT_RECVBUF, 1) == 0); So(nng_setopt_int(s1, NNG_OPT_SENDBUF, 1) == 0); So(nng_setopt_int(c1, NNG_OPT_RECVBUF, 1) == 0); - So(nng_setopt_usec(s1, NNG_OPT_SENDTIMEO, 100000) == - 0); + So(nng_setopt_ms(s1, NNG_OPT_SENDTIMEO, to) == 0); So(nng_listen(s1, addr, NULL, 0) == 0); So(nng_dial(c1, addr, NULL, 0) == 0); - nng_usleep(20000); + nng_msleep(20); for (i = 0, rv = 0; i < 10; i++) { So(nng_msg_alloc(&msg, 0) == 0); @@ -132,18 +135,19 @@ TestMain("PAIRv1 protocol", { }); Convey("Monogamous mode exerts backpressure", { - int i; - int rv; - nng_msg *msg; + int i; + int rv; + nng_msg * msg; + nng_duration to = MILLISECOND(30); So(nng_setopt_int(s1, NNG_OPT_RECVBUF, 1) == 0); So(nng_setopt_int(s1, NNG_OPT_SENDBUF, 1) == 0); So(nng_setopt_int(c1, NNG_OPT_RECVBUF, 1) == 0); - So(nng_setopt_usec(s1, NNG_OPT_SENDTIMEO, 30000) == 0); + So(nng_setopt_ms(s1, NNG_OPT_SENDTIMEO, to) == 0); So(nng_listen(s1, addr, NULL, 0) == 0); So(nng_dial(c1, addr, NULL, 0) == 0); - nng_usleep(20000); + nng_msleep(20); // We choose to allow some buffering. In reality the // buffer size is just 1, and we will fail after 2. @@ -161,7 +165,7 @@ TestMain("PAIRv1 protocol", { Convey("Cannot set polyamorous mode after connect", { So(nng_listen(s1, addr, NULL, 0) == 0); So(nng_dial(c1, addr, NULL, 0) == 0); - nng_usleep(100000); + nng_msleep(100); So(nng_setopt_int(s1, NNG_OPT_PAIR1_POLY, 1) == NNG_ESTATE); @@ -177,7 +181,7 @@ TestMain("PAIRv1 protocol", { So(nng_listen(s1, addr, NULL, 0) == 0); So(nng_dial(c1, addr, NULL, 0) == 0); - nng_usleep(20000); + nng_msleep(20); Convey("Send/recv work", { So(nng_msg_alloc(&msg, 0) == 0); @@ -343,7 +347,7 @@ TestMain("PAIRv1 protocol", { So(nng_listen(s1, addr, NULL, 0) == 0); So(nng_dial(c1, addr, NULL, 0) == 0); So(nng_dial(c2, addr, NULL, 0) == 0); - nng_usleep(20000); + nng_msleep(20); So(nng_msg_alloc(&msg, 0) == 0); APPENDSTR(msg, "ONE"); @@ -398,9 +402,9 @@ TestMain("PAIRv1 protocol", { So(nng_listen(s1, addr, NULL, 0) == 0); So(nng_dial(c1, addr, NULL, 0) == 0); - nng_usleep(100000); + nng_msleep(100); So(nng_dial(c2, addr, NULL, 0) == 0); - nng_usleep(20000); + nng_msleep(20); So(nng_msg_alloc(&msg, 0) == 0); APPENDSTR(msg, "YES"); @@ -410,7 +414,7 @@ TestMain("PAIRv1 protocol", { nng_msg_free(msg); nng_close(c1); - nng_usleep(10000); + nng_msleep(10); So(nng_msg_alloc(&msg, 0) == 0); APPENDSTR(msg, "AGAIN"); @@ -442,7 +446,7 @@ TestMain("PAIRv1 protocol", { So(nng_listen(s1, addr, NULL, 0) == 0); So(nng_dial(c1, addr, NULL, 0) == 0); So(nng_dial(c2, addr, NULL, 0) == 0); - nng_usleep(20000); + nng_msleep(20); Convey("Send/recv works", { So(nng_msg_alloc(&msg, 0) == 0); diff --git a/tests/pipeline.c b/tests/pipeline.c index c7ac2dd0..a7718dd6 100644 --- a/tests/pipeline.c +++ b/tests/pipeline.c @@ -16,6 +16,7 @@ #define CHECKSTR(m, s) \ So(nng_msg_len(m) == strlen(s)); \ So(memcmp(nng_msg_body(m), s, strlen(s)) == 0) +#define MILLISECOND(x) (x) TestMain("PIPELINE (PUSH/PULL) pattern", { atexit(nng_fini); @@ -80,7 +81,7 @@ TestMain("PIPELINE (PUSH/PULL) pattern", { So(nng_dial(what, addr, NULL, 0) == 0); So(nng_shutdown(what) == 0); - nng_usleep(20000); + nng_msleep(20); Convey("Push can send messages, and pull can recv", { nng_msg *msg; @@ -97,13 +98,13 @@ TestMain("PIPELINE (PUSH/PULL) pattern", { }); Convey("Load balancing", { - nng_msg * abc; - nng_msg * def; - uint64_t usecs; - nng_socket push; - nng_socket pull1; - nng_socket pull2; - nng_socket pull3; + nng_msg * abc; + nng_msg * def; + nng_duration msecs; + nng_socket push; + nng_socket pull1; + nng_socket pull2; + nng_socket pull3; So(nng_push_open(&push) == 0); So(nng_pull_open(&pull1) == 0); @@ -137,10 +138,10 @@ TestMain("PIPELINE (PUSH/PULL) pattern", { So(nng_msg_alloc(&def, 0) == 0); APPENDSTR(def, "def"); - usecs = 100000; - So(nng_setopt_usec(pull1, NNG_OPT_RECVTIMEO, usecs) == 0); - So(nng_setopt_usec(pull2, NNG_OPT_RECVTIMEO, usecs) == 0); - So(nng_setopt_usec(pull3, NNG_OPT_RECVTIMEO, usecs) == 0); + msecs = MILLISECOND(100); + So(nng_setopt_ms(pull1, NNG_OPT_RECVTIMEO, msecs) == 0); + So(nng_setopt_ms(pull2, NNG_OPT_RECVTIMEO, msecs) == 0); + So(nng_setopt_ms(pull3, NNG_OPT_RECVTIMEO, msecs) == 0); So(nng_listen(push, addr, NULL, 0) == 0); So(nng_dial(pull1, addr, NULL, 0) == 0); So(nng_dial(pull2, addr, NULL, 0) == 0); @@ -152,7 +153,7 @@ TestMain("PIPELINE (PUSH/PULL) pattern", { // server couldn't have gotten to the accept. (The // accept logic is single threaded.) Let's wait a bit // though, to ensure that stuff has settled. - nng_usleep(100000); + nng_msleep(100); So(nng_sendmsg(push, abc, 0) == 0); So(nng_sendmsg(push, def, 0) == 0); diff --git a/tests/platform.c b/tests/platform.c index a28bc4e4..74dbab50 100644 --- a/tests/platform.c +++ b/tests/platform.c @@ -11,34 +11,7 @@ #include "convey.h" #include "core/nng_impl.h" #include "nng.h" - -#ifndef _WIN32 -#include -#endif - -uint64_t -getms(void) -{ -#ifdef _WIN32 - return (GetTickCount64()); -#else - static time_t epoch; - struct timeval tv; - - if (epoch == 0) { - epoch = time(NULL); - } - gettimeofday(&tv, NULL); - - if (tv.tv_sec < epoch) { - // Broken clock. - // This will force all other timing tests to fail - return (0); - } - tv.tv_sec -= epoch; - return (((uint64_t)(tv.tv_sec) * 1000) + (tv.tv_usec / 1000)); -#endif -} +#include "stubs.h" // Add is for testing threads. void @@ -49,10 +22,10 @@ add(void *arg) // Notify tests for verifying condvars. struct notifyarg { - int did; - int when; - nni_mtx mx; - nni_cv cv; + int did; + nng_duration when; + nni_mtx mx; + nni_cv cv; }; void @@ -60,7 +33,7 @@ notifyafter(void *arg) { struct notifyarg *na = arg; - nni_usleep(na->when); + nng_msleep(na->when); nni_mtx_lock(&na->mx); na->did = 1; nni_cv_wake(&na->cv); @@ -76,7 +49,7 @@ TestMain("Platform Operations", { uint64_t now = getms(); Convey("usleep works", { - nni_usleep(100000); + nng_msleep(100); So((getms() - now) >= 100); // cannot be *shorter*!! So((getms() - now) < 150); // crummy clock resolution? @@ -87,14 +60,14 @@ TestMain("Platform Operations", { int msdelta; nni_time usend; nni_time usnow = nni_clock(); - nni_usleep(200000); + nng_msleep(200); usend = nni_clock(); msend = getms(); So(usend > usnow); So(msend > now); - usdelta = (int) ((usend - usnow) / 1000); - msdelta = (int) ((msend - now)); + usdelta = (int) (usend - usnow); + msdelta = (int) (msend - now); So(usdelta >= 200); So(usdelta < 220); So(abs(msdelta - usdelta) < 20); @@ -135,7 +108,7 @@ TestMain("Platform Operations", { Reset({ nni_thr_fini(&thr); }); Convey("It ran", { - nni_usleep(50000); // for context switch + nng_msleep(50); // for context switch So(val == 1); }); }); @@ -156,7 +129,7 @@ TestMain("Platform Operations", { Convey("Notification works", { arg.did = 0; - arg.when = 10000; + arg.when = 10; nni_thr_run(&thr); nni_mtx_lock(&arg.mx); @@ -170,11 +143,11 @@ TestMain("Platform Operations", { Convey("Timeout works", { arg.did = 0; - arg.when = 200000; + arg.when = 200; nni_thr_run(&thr); nni_mtx_lock(&arg.mx); if (!arg.did) { - nni_cv_until(&arg.cv, nni_clock() + 10000); + nni_cv_until(&arg.cv, nni_clock() + 10); } So(arg.did == 0); nni_mtx_unlock(&arg.mx); @@ -185,7 +158,7 @@ TestMain("Platform Operations", { arg.when = 1; nni_mtx_lock(&arg.mx); if (!arg.did) { - nni_cv_until(&arg.cv, nni_clock() + 10000); + nni_cv_until(&arg.cv, nni_clock() + 10); } So(arg.did == 0); nni_mtx_unlock(&arg.mx); diff --git a/tests/pollfd.c b/tests/pollfd.c index e5130f57..e1965b09 100644 --- a/tests/pollfd.c +++ b/tests/pollfd.c @@ -45,10 +45,8 @@ TestMain("Poll FDs", { nng_close(s2); }); So(nng_listen(s1, "inproc://yeahbaby", NULL, 0) == 0); - nng_usleep(50000); - So(nng_dial(s2, "inproc://yeahbaby", NULL, 0) == 0); - nng_usleep(50000); + nng_msleep(50); Convey("We can get a recv FD", { int fd; diff --git a/tests/pubsub.c b/tests/pubsub.c index 0c59f10e..e79c3f1d 100644 --- a/tests/pubsub.c +++ b/tests/pubsub.c @@ -81,7 +81,7 @@ TestMain("PUB/SUB pattern", { So(nng_listen(sub, addr, NULL, 0) == 0); So(nng_dial(pub, addr, NULL, 0) == 0); - nng_usleep(20000); // give time for connecting threads + nng_msleep(20); // give time for connecting threads Convey("Sub can subscribe", { So(nng_setopt(sub, NNG_OPT_SUB_SUBSCRIBE, "ABC", 3) == @@ -110,8 +110,7 @@ TestMain("PUB/SUB pattern", { So(nng_setopt(sub, NNG_OPT_SUB_SUBSCRIBE, "/some/", strlen("/some/")) == 0); - So(nng_setopt_usec(sub, NNG_OPT_RECVTIMEO, 90000) == - 0); + So(nng_setopt_ms(sub, NNG_OPT_RECVTIMEO, 90) == 0); So(nng_msg_alloc(&msg, 0) == 0); APPENDSTR(msg, "/some/like/it/hot"); @@ -140,8 +139,7 @@ TestMain("PUB/SUB pattern", { Convey("Subs without subsciptions don't receive", { nng_msg *msg; - So(nng_setopt_usec(sub, NNG_OPT_RECVTIMEO, 90000) == - 0); + So(nng_setopt_ms(sub, NNG_OPT_RECVTIMEO, 90) == 0); So(nng_msg_alloc(&msg, 0) == 0); APPENDSTR(msg, "/some/don't/like/it"); @@ -153,8 +151,7 @@ TestMain("PUB/SUB pattern", { nng_msg *msg; - So(nng_setopt_usec(sub, NNG_OPT_RECVTIMEO, 90000) == - 0); + So(nng_setopt_ms(sub, NNG_OPT_RECVTIMEO, 90) == 0); So(nng_setopt_int(sub, NNG_OPT_RAW, 1) == 0); So(nng_msg_alloc(&msg, 0) == 0); diff --git a/tests/reconnect.c b/tests/reconnect.c index 4324a84b..8179055d 100644 --- a/tests/reconnect.c +++ b/tests/reconnect.c @@ -32,18 +32,18 @@ TestMain("Reconnect works", { nng_close(pull); }); - So(nng_setopt_usec(pull, NNG_OPT_RECONNMINT, 10000) == 0); - So(nng_setopt_usec(pull, NNG_OPT_RECONNMAXT, 10000) == 0); + So(nng_setopt_ms(pull, NNG_OPT_RECONNMINT, 10) == 0); + So(nng_setopt_ms(pull, NNG_OPT_RECONNMAXT, 10) == 0); Convey("Dialing before listening works", { So(nng_dial(push, addr, NULL, NNG_FLAG_NONBLOCK) == 0); - nng_usleep(100000); + nng_msleep(100); So(nng_listen(pull, addr, NULL, 0) == 0); Convey("We can send a frame", { nng_msg *msg; - nng_usleep(100000); + nng_msleep(100); So(nng_msg_alloc(&msg, 0) == 0); APPENDSTR(msg, "hello"); So(nng_sendmsg(push, msg, 0) == 0); @@ -58,7 +58,7 @@ TestMain("Reconnect works", { nng_listener l; So(nng_dial(push, addr, NULL, NNG_FLAG_NONBLOCK) == 0); So(nng_listen(pull, addr, &l, 0) == 0); - nng_usleep(100000); + nng_msleep(100); nng_listener_close(l); So(nng_listen(pull, addr, NULL, 0) == 0); @@ -66,7 +66,7 @@ TestMain("Reconnect works", { nng_msg *msg; nng_pipe p1; - nng_usleep(100000); + nng_msleep(100); So(nng_msg_alloc(&msg, 0) == 0); APPENDSTR(msg, "hello"); So(nng_sendmsg(push, msg, 0) == 0); @@ -81,7 +81,7 @@ TestMain("Reconnect works", { nng_pipe p2; nng_pipe_close(p1); - nng_usleep(100000); + nng_msleep(100); So(nng_msg_alloc(&msg, 0) == 0); APPENDSTR(msg, "again"); So(nng_sendmsg(push, msg, 0) == 0); diff --git a/tests/reqrep.c b/tests/reqrep.c index c31f0212..ada21875 100644 --- a/tests/reqrep.c +++ b/tests/reqrep.c @@ -31,8 +31,8 @@ TestMain("REQ/REP pattern", { Convey("Resend time option id works", { // Set timeout. - So(nng_setopt_usec( - req, NNG_OPT_REQ_RESENDTIME, 10000) == 0); + So(nng_setopt_ms(req, NNG_OPT_REQ_RESENDTIME, 10) == + 0); // Check invalid size So(nng_setopt(req, NNG_OPT_REQ_RESENDTIME, "", 1) == NNG_EINVAL); @@ -66,7 +66,7 @@ TestMain("REQ/REP pattern", { }); Convey("Cannot set resend time", { - So(nng_setopt_usec(rep, NNG_OPT_REQ_RESENDTIME, 100) == + So(nng_setopt_ms(rep, NNG_OPT_REQ_RESENDTIME, 100) == NNG_ENOTSUP); }); }); @@ -114,10 +114,10 @@ TestMain("REQ/REP pattern", { }); Convey("Request cancellation works", { - nng_msg *abc; - nng_msg *def; - nng_msg *cmd; - uint64_t retry = 100000; // 100 ms + nng_msg * abc; + nng_msg * def; + nng_msg * cmd; + nng_duration retry = 100; // 100 ms nng_socket req; nng_socket rep; @@ -131,7 +131,7 @@ TestMain("REQ/REP pattern", { nng_close(req); }); - So(nng_setopt_usec(req, NNG_OPT_REQ_RESENDTIME, retry) == 0); + So(nng_setopt_ms(req, NNG_OPT_REQ_RESENDTIME, retry) == 0); So(nng_setopt_int(req, NNG_OPT_SENDBUF, 16) == 0); So(nng_msg_alloc(&abc, 0) == 0); diff --git a/tests/scalability.c b/tests/scalability.c index 22b66d10..b1a9b767 100644 --- a/tests/scalability.c +++ b/tests/scalability.c @@ -48,15 +48,15 @@ stop(void) int openclients(nng_socket *clients, int num) { - int rv; - int i; - uint64_t t; + int rv; + int i; + nng_duration t; for (i = 0; i < num; i++) { - t = 100000; // 100ms + t = 100; // 100ms nng_socket c; if (((rv = nng_req_open(&c)) != 0) || - ((rv = nng_setopt_usec(c, NNG_OPT_RECVTIMEO, t)) != 0) || - ((rv = nng_setopt_usec(c, NNG_OPT_SENDTIMEO, t)) != 0) || + ((rv = nng_setopt_ms(c, NNG_OPT_RECVTIMEO, t)) != 0) || + ((rv = nng_setopt_ms(c, NNG_OPT_SENDTIMEO, t)) != 0) || ((rv = nng_dial(c, addr, NULL, 0)) != 0)) { return (rv); } diff --git a/tests/sock.c b/tests/sock.c index e21e687d..341bd263 100644 --- a/tests/sock.c +++ b/tests/sock.c @@ -12,8 +12,12 @@ #include "nng.h" #include "trantest.h" +#include "stubs.h" + #include +#define SECONDS(x) ((x) *1000) + TestMain("Socket Operations", { atexit(nng_fini); @@ -58,17 +62,17 @@ TestMain("Socket Operations", { }); Convey("Recv with no pipes times out correctly", { - nng_msg *msg = NULL; - int64_t to = 100000; - uint64_t now; + nng_msg * msg = NULL; + nng_duration to = 100; + uint64_t now; - now = nng_clock(); + now = getms(); So(now > 0); - So(nng_setopt_usec(s1, NNG_OPT_RECVTIMEO, to) == 0); + So(nng_setopt_ms(s1, NNG_OPT_RECVTIMEO, to) == 0); So(nng_recvmsg(s1, &msg, 0) == NNG_ETIMEDOUT); So(msg == NULL); - So(nng_clock() >= (now + to)); - So(nng_clock() < (now + (to * 2))); + So(getms() >= (now + to)); + So(getms() < (now + (to * 2))); }); Convey("Recv nonblock with no pipes gives EAGAIN", { @@ -79,28 +83,28 @@ TestMain("Socket Operations", { }); Convey("Send with no pipes times out correctly", { - nng_msg *msg = NULL; - int64_t to = 100000; - uint64_t now; + nng_msg * msg = NULL; + nng_duration to = 100; + uint64_t now; // We cheat to get access to the core's clock. So(nng_msg_alloc(&msg, 0) == 0); So(msg != NULL); - now = nng_clock(); + now = getms(); - So(nng_setopt_usec(s1, NNG_OPT_SENDTIMEO, to) == 0); + So(nng_setopt_ms(s1, NNG_OPT_SENDTIMEO, to) == 0); So(nng_sendmsg(s1, msg, 0) == NNG_ETIMEDOUT); - So(nng_clock() >= (now + to)); - So(nng_clock() < (now + (to * 2))); + So(getms() >= (now + to)); + So(getms() < (now + (to * 2))); nng_msg_free(msg); }); Convey("We can set and get options", { - int64_t to = 1234; - int64_t v = 0; - size_t sz; + nng_duration to = 1234; + int64_t v = 0; + size_t sz; - So(nng_setopt_usec(s1, NNG_OPT_SENDTIMEO, to) == 0); + So(nng_setopt_ms(s1, NNG_OPT_SENDTIMEO, to) == 0); Convey("Read only options handled properly", { So(nng_setopt_int(s1, NNG_OPT_RECVFD, 0) == @@ -217,27 +221,28 @@ TestMain("Socket Operations", { }); Convey("Short size is not copied", { sz = 0; + to = 0; So(nng_getopt( - s1, NNG_OPT_SENDTIMEO, &v, &sz) == 0); - So(sz == sizeof(v)); - So(v == 0); + s1, NNG_OPT_SENDTIMEO, &to, &sz) == 0); + So(sz == sizeof(to)); + So(to == 0); sz = 0; So(nng_getopt( - s1, NNG_OPT_RECONNMINT, &v, &sz) == 0); + s1, NNG_OPT_RECONNMINT, &to, &sz) == 0); - So(v == 0); + So(to == 0); sz = 0; So(nng_getopt( - s1, NNG_OPT_RECONNMAXT, &v, &sz) == 0); - So(v == 0); + s1, NNG_OPT_RECONNMAXT, &to, &sz) == 0); + So(to == 0); }); Convey("Correct size is copied", { - sz = sizeof(v); + sz = sizeof(to); So(nng_getopt( - s1, NNG_OPT_SENDTIMEO, &v, &sz) == 0); - So(sz == sizeof(v)); - So(v == 1234); + s1, NNG_OPT_SENDTIMEO, &to, &sz) == 0); + So(sz == sizeof(to)); + So(to == 1234); }); Convey("Short size buf is not copied", { @@ -257,8 +262,8 @@ TestMain("Socket Operations", { }); Convey("Negative timeout fails", { - So(nng_setopt_usec(s1, NNG_OPT_RECVTIMEO, - -5) == NNG_EINVAL); + So(nng_setopt_ms(s1, NNG_OPT_RECVTIMEO, -5) == + NNG_EINVAL); }); Convey("Short timeout fails", { @@ -346,7 +351,7 @@ TestMain("Socket Operations", { So(nng_pair_open(&s2) == 0); Reset({ nng_close(s2); }); So(nng_listen(s2, a, NULL, 0) == 0); - nng_usleep(100000); + nng_msleep(100); So(nng_send(s1, "abc", 4, 0) == 0); So(nng_recv(s2, &buf, &sz, NNG_FLAG_ALLOC) == 0); @@ -396,8 +401,8 @@ TestMain("Socket Operations", { // Not appropriate for dialer. So(nng_dialer_setopt_int(ep, NNG_OPT_RAW, 1) == NNG_ENOTSUP); - So(nng_dialer_setopt_usec(ep, - NNG_OPT_RECONNMINT, 1) == NNG_ENOTSUP); + So(nng_dialer_setopt_ms(ep, NNG_OPT_RECONNMINT, + 1) == NNG_ENOTSUP); }); Convey("Bad size checks", { So(nng_dialer_setopt(ep, NNG_OPT_RECVMAXSZ, @@ -424,7 +429,7 @@ TestMain("Socket Operations", { // Not appropriate for dialer. So(nng_listener_setopt_int( ep, NNG_OPT_RAW, 1) == NNG_ENOTSUP); - So(nng_listener_setopt_usec(ep, + So(nng_listener_setopt_ms(ep, NNG_OPT_RECONNMINT, 1) == NNG_ENOTSUP); }); Convey("Bad size checks", { @@ -436,9 +441,9 @@ TestMain("Socket Operations", { }); Convey("Cannot access absent ep options", { - size_t s; - int i; - uint64_t t; + size_t s; + int i; + nng_duration t; So(nng_dialer_setopt_size( 1999, NNG_OPT_RECVMAXSZ, 10) == NNG_ENOENT); @@ -461,20 +466,20 @@ TestMain("Socket Operations", { So(nng_listener_getopt_int(1999, NNG_OPT_RAW, &i) == NNG_ENOENT); - So(nng_dialer_getopt_usec(1999, NNG_OPT_LINGER, &t) == + So(nng_dialer_getopt_ms(1999, NNG_OPT_LINGER, &t) == + NNG_ENOENT); + So(nng_listener_getopt_ms(1999, NNG_OPT_LINGER, &t) == NNG_ENOENT); - So(nng_listener_getopt_usec( - 1999, NNG_OPT_LINGER, &t) == NNG_ENOENT); }); Convey("We can send and receive messages", { - nng_socket s2; - int len; - size_t sz; - uint64_t to = 3000000; - char * buf; - char * a = "inproc://t1"; + nng_socket s2; + int len; + size_t sz; + nng_duration to = SECONDS(3); + char * buf; + char * a = "inproc://t1"; So(nng_pair_open(&s2) == 0); Reset({ nng_close(s2); }); @@ -486,10 +491,10 @@ TestMain("Socket Operations", { So(nng_setopt_int(s1, NNG_OPT_SENDBUF, 1) == 0); So(nng_setopt_int(s2, NNG_OPT_SENDBUF, 1) == 0); - So(nng_setopt_usec(s1, NNG_OPT_SENDTIMEO, to) == 0); - So(nng_setopt_usec(s1, NNG_OPT_RECVTIMEO, to) == 0); - So(nng_setopt_usec(s2, NNG_OPT_SENDTIMEO, to) == 0); - So(nng_setopt_usec(s2, NNG_OPT_RECVTIMEO, to) == 0); + So(nng_setopt_ms(s1, NNG_OPT_SENDTIMEO, to) == 0); + So(nng_setopt_ms(s1, NNG_OPT_RECVTIMEO, to) == 0); + So(nng_setopt_ms(s2, NNG_OPT_SENDTIMEO, to) == 0); + So(nng_setopt_ms(s2, NNG_OPT_RECVTIMEO, to) == 0); So(nng_listen(s1, a, NULL, 0) == 0); So(nng_dial(s2, a, NULL, 0) == 0); diff --git a/tests/stubs.h b/tests/stubs.h index c77b8db6..780ac772 100644 --- a/tests/stubs.h +++ b/tests/stubs.h @@ -10,12 +10,12 @@ #ifndef STUBS_H #define STUBS_H -#include -#ifdef _WIN32 +#ifdef _WIN32 #include #else -#include +#include #include +#include #endif // Stub handlers for some common things. @@ -23,10 +23,10 @@ uint64_t getms(void) { -#ifdef _WIN32 - return (GetTickCount64()) ; +#ifdef _WIN32 + return (GetTickCount64()); #else - static time_t epoch; + static time_t epoch; struct timeval tv; if (epoch == 0) { @@ -40,8 +40,8 @@ getms(void) return (0); } tv.tv_sec -= epoch; - return (((uint64_t)(tv.tv_sec ) * 1000) + (tv.tv_usec / 1000)); + return (((uint64_t)(tv.tv_sec) * 1000) + (tv.tv_usec / 1000)); #endif } -#endif // STUBS_H \ No newline at end of file +#endif // STUBS_H diff --git a/tests/survey.c b/tests/survey.c index 83971818..6658d488 100644 --- a/tests/survey.c +++ b/tests/survey.c @@ -43,8 +43,8 @@ TestMain("SURVEY pattern", { Convey("Survey without responder times out", { nng_msg *msg; - So(nng_setopt_usec( - surv, NNG_OPT_SURVEYOR_SURVEYTIME, 50000) == 0); + So(nng_setopt_ms( + surv, NNG_OPT_SURVEYOR_SURVEYTIME, 50) == 0); So(nng_msg_alloc(&msg, 0) == 0); So(nng_sendmsg(surv, msg, 0) == 0); So(nng_recvmsg(surv, &msg, 0) == NNG_ETIMEDOUT); @@ -83,8 +83,7 @@ TestMain("SURVEY pattern", { nng_close(resp); }); - So(nng_setopt_usec(surv, NNG_OPT_SURVEYOR_SURVEYTIME, 50000) == - 0); + So(nng_setopt_ms(surv, NNG_OPT_SURVEYOR_SURVEYTIME, 50) == 0); So(nng_listen(surv, addr, NULL, 0) == 0); So(nng_dial(resp, addr, NULL, 0) == 0); @@ -98,7 +97,6 @@ TestMain("SURVEY pattern", { Convey("Survey works", { nng_msg *msg; - uint64_t rtimeo; So(nng_msg_alloc(&msg, 0) == 0); APPENDSTR(msg, "abc"); @@ -117,9 +115,8 @@ TestMain("SURVEY pattern", { So(nng_recvmsg(surv, &msg, 0) == NNG_ETIMEDOUT); Convey("And goes to non-survey state", { - rtimeo = 200000; - So(nng_setopt_usec( - surv, NNG_OPT_RECVTIMEO, 200000) == 0); + So(nng_setopt_ms( + surv, NNG_OPT_RECVTIMEO, 200) == 0); So(nng_recvmsg(surv, &msg, 0) == NNG_ESTATE); }); }); diff --git a/tests/synch.c b/tests/synch.c index d861f04d..b1d0d66a 100644 --- a/tests/synch.c +++ b/tests/synch.c @@ -14,10 +14,10 @@ // Notify tests for verifying condvars. struct notifyarg { - int did; - int when; - nni_mtx mx; - nni_cv cv; + int did; + nng_duration when; + nni_mtx mx; + nni_cv cv; }; #ifdef NNG_PLATFORM_POSIX @@ -31,7 +31,7 @@ notifyafter(void *arg) { struct notifyarg *na = arg; - nni_usleep(na->when); + nni_msleep(na->when); nni_mtx_lock(&na->mx); na->did = 1; nni_cv_wake(&na->cv); @@ -71,10 +71,10 @@ test_sync(void) arg.when = 0; nni_mtx_lock(&arg.mx); nni_thr_run(&thr); - nng_usleep(10000); + nng_msleep(10); So(arg.did == 0); nni_mtx_unlock(&arg.mx); - nng_usleep(10000); + nng_msleep(10); nni_mtx_lock(&arg.mx); while (!arg.did) { nni_cv_wait(&arg.cv); @@ -103,7 +103,7 @@ test_sync(void) Convey("Notification works", { arg.did = 0; - arg.when = 10000; + arg.when = 10; nni_thr_run(&thr); nni_mtx_lock(&arg.mx); @@ -117,11 +117,11 @@ test_sync(void) Convey("Timeout works", { arg.did = 0; - arg.when = 200000; + arg.when = 200; nni_thr_run(&thr); nni_mtx_lock(&arg.mx); if (!arg.did) { - nni_cv_until(&arg.cv, nni_clock() + 10000); + nni_cv_until(&arg.cv, nni_clock() + 10); } So(arg.did == 0); nni_mtx_unlock(&arg.mx); @@ -139,7 +139,7 @@ test_sync(void) arg.when = 1; nni_mtx_lock(&arg.mx); if (!arg.did) { - nni_cv_until(&arg.cv, nni_clock() + 10000); + nni_cv_until(&arg.cv, nni_clock() + 10); } So(arg.did == 0); nni_mtx_unlock(&arg.mx); @@ -184,10 +184,10 @@ test_sync_fallback(void) arg.when = 0; nni_mtx_lock(&arg.mx); nni_thr_run(&thr); - nng_usleep(10000); + nng_msleep(10); So(arg.did == 0); nni_mtx_unlock(&arg.mx); - nng_usleep(10000); + nng_msleep(10); nni_mtx_lock(&arg.mx); while (!arg.did) { nni_cv_wait(&arg.cv); @@ -216,7 +216,7 @@ test_sync_fallback(void) Convey("Notification works", { arg.did = 0; - arg.when = 10000; + arg.when = 10; nni_thr_run(&thr); nni_mtx_lock(&arg.mx); @@ -230,11 +230,11 @@ test_sync_fallback(void) Convey("Timeout works", { arg.did = 0; - arg.when = 200000; + arg.when = 200; nni_thr_run(&thr); nni_mtx_lock(&arg.mx); if (!arg.did) { - nni_cv_until(&arg.cv, nni_clock() + 10000); + nni_cv_until(&arg.cv, nni_clock() + 10); } So(arg.did == 0); nni_mtx_unlock(&arg.mx); @@ -252,7 +252,7 @@ test_sync_fallback(void) arg.when = 1; nni_mtx_lock(&arg.mx); if (!arg.did) { - nni_cv_until(&arg.cv, nni_clock() + 10000); + nni_cv_until(&arg.cv, nni_clock() + 10); } So(arg.did == 0); nni_mtx_unlock(&arg.mx); @@ -278,7 +278,7 @@ TestMain("Synchronization", { So(nni_thr_init(&thr, notifyafter, &arg) == 0); arg.did = 0; - arg.when = 10000; + arg.when = 10; nni_thr_run(&thr); nni_mtx_lock(&arg.mx); diff --git a/tests/trantest.h b/tests/trantest.h index 52b6b2ea..37763d24 100644 --- a/tests/trantest.h +++ b/tests/trantest.h @@ -139,7 +139,7 @@ trantest_send_recv(trantest *tt) So(nng_dial(tt->reqsock, tt->addr, &d, 0) == 0); So(d != 0); - nng_usleep(20000); // listener may be behind slightly + nng_msleep(20); // listener may be behind slightly send = NULL; So(nng_msg_alloc(&send, 0) == 0); @@ -186,7 +186,7 @@ trantest_check_properties(trantest *tt, trantest_proptest_t f) So(nng_dial(tt->reqsock, tt->addr, &d, 0) == 0); So(d != 0); - nng_usleep(20000); // listener may be behind slightly + nng_msleep(20); // listener may be behind slightly send = NULL; So(nng_msg_alloc(&send, 0) == 0); @@ -228,7 +228,7 @@ trantest_send_recv_large(trantest *tt) So(nng_dial(tt->reqsock, tt->addr, &d, 0) == 0); So(d != 0); - nng_usleep(20000); // listener may be behind slightly + nng_msleep(20); // listener may be behind slightly send = NULL; So(nng_msg_alloc(&send, size) == 0); diff --git a/tests/udp.c b/tests/udp.c index e343bbab..639d8da8 100644 --- a/tests/udp.c +++ b/tests/udp.c @@ -162,7 +162,7 @@ TestMain("UDP support", { nni_plat_udp_send(u1, aio2); // This delay here is required to test for a race // condition that does not occur if it is absent. - nng_usleep(200); + nng_msleep(1); nni_plat_udp_send(u1, aio1); nni_aio_wait(aio2); diff --git a/tests/zt.c b/tests/zt.c index 9e6557bc..562f4ee1 100644 --- a/tests/zt.c +++ b/tests/zt.c @@ -119,34 +119,32 @@ check_props(nng_msg *msg, nng_listener l, nng_dialer d) }); Convey("Ping properties work", { - int c; - uint64_t u; + int c; + nng_duration t; + z = sizeof(c); c = 0; So(nng_pipe_getopt(p, NNG_OPT_ZT_PING_COUNT, &c, &z) == 0); So(c > 0 && c < 10); // actually 5... - z = sizeof(u); - u = 0; - So(nng_pipe_getopt(p, NNG_OPT_ZT_PING_TIME, &u, &z) == 0); - So(u > 1000000 && u < 3600000000ull); // 1 sec - 1 hour + t = 0; + So(nng_pipe_getopt_ms(p, NNG_OPT_ZT_PING_TIME, &t) == 0); + So(t > 1000 && t < 3600000); // 1 sec - 1 hour c = 0; So(nng_dialer_getopt_int(d, NNG_OPT_ZT_PING_COUNT, &c) == 0); So(c > 0 && c < 10); // actually 5... - z = sizeof(u); - u = 0; - So(nng_dialer_getopt_usec(d, NNG_OPT_ZT_PING_TIME, &u) == 0); - So(u > 1000000 && u < 3600000000ull); // 1 sec - 1 hour + t = 0; + So(nng_dialer_getopt_ms(d, NNG_OPT_ZT_PING_TIME, &t) == 0); + So(t > 1000 && t < 3600000); // 1 sec - 1 hour int rv = nng_dialer_setopt_int(d, NNG_OPT_ZT_PING_COUNT, 20); So(nng_dialer_setopt_int(d, NNG_OPT_ZT_PING_COUNT, 20) == 0); - So(nng_dialer_setopt_usec(d, NNG_OPT_ZT_PING_TIME, 2000000) == - 0); + So(nng_dialer_setopt_ms(d, NNG_OPT_ZT_PING_TIME, 2000) == 0); So(nng_listener_setopt_int(l, NNG_OPT_ZT_PING_COUNT, 0) == 0); - So(nng_listener_setopt_usec(l, NNG_OPT_ZT_PING_TIME, 0) == 0); + So(nng_listener_setopt_ms(l, NNG_OPT_ZT_PING_TIME, 0) == 0); }); Convey("Home property works", { @@ -221,13 +219,15 @@ TestMain("ZeroTier Transport", { ids[0] = 0x622514484aull; ids[1] = 0x622514484aull; - So(nng_listener_setopt(l, NNG_OPT_ZT_ORBIT, ids, sizeof (ids)) == 0); + So(nng_listener_setopt(l, NNG_OPT_ZT_ORBIT, + ids, sizeof(ids)) == 0); }); Convey("And we can deorbit anything", { uint64_t id; id = 0x12345678; - So(nng_listener_setopt(l, NNG_OPT_ZT_DEORBIT, &id, sizeof (id)) == 0); + So(nng_listener_setopt(l, NNG_OPT_ZT_DEORBIT, + &id, sizeof(id)) == 0); }); }); }); @@ -265,7 +265,8 @@ TestMain("ZeroTier Transport", { So(nng_listener_create(&l, s, addr) == 0); - So(nng_listener_getopt_usec(l, NNG_OPT_ZT_NODE, &node1) == 0); + So(nng_listener_getopt_uint64(l, NNG_OPT_ZT_NODE, &node1) == + 0); So(node1 != 0); Convey("Network name & status options work", { @@ -274,7 +275,7 @@ TestMain("ZeroTier Transport", { int status; namesz = sizeof(name); - nng_usleep(10000000); + nng_msleep(10000); So(nng_listener_getopt(l, NNG_OPT_ZT_NETWORK_NAME, name, &namesz) == 0); So(strcmp(name, "nng_test_open") == 0); @@ -286,7 +287,7 @@ TestMain("ZeroTier Transport", { snprintf(addr, sizeof(addr), "zt://" NWID "/%llx:%u", (unsigned long long) node1, 42u); So(nng_dialer_create(&d, s, addr) == 0); - So(nng_dialer_getopt_usec( + So(nng_dialer_getopt_uint64( d, NNG_OPT_ZT_NODE, &node2) == 0); So(node2 == node1); So(nng_dialer_start(d, 0) == NNG_ECONNREFUSED); @@ -314,7 +315,7 @@ TestMain("ZeroTier Transport", { nng_close(s1); // This sleep allows us to ensure disconnect // messages work. - nng_usleep(500000); + nng_msleep(500); nng_close(s2); }); @@ -324,16 +325,16 @@ TestMain("ZeroTier Transport", { So(nng_listener_start(l, 0) == 0); node = 0; - So(nng_listener_getopt_usec(l, NNG_OPT_ZT_NODE, &node) == 0); + So(nng_listener_getopt_uint64(l, NNG_OPT_ZT_NODE, &node) == 0); So(node != 0); - + nng_msleep(40); snprintf(addr2, sizeof(addr2), "zt://" NWID "/%llx:%u", (unsigned long long) node, port); So(nng_dialer_create(&d, s2, addr2) == 0); So(nng_dialer_setopt( d, NNG_OPT_ZT_HOME, path2, strlen(path2) + 1) == 0); So(nng_dialer_start(d, 0) == 0); - nng_usleep(2000000); + nng_msleep(2000); }); trantest_test_extended("zt://" NWID "/*:%u", check_props); -- cgit v1.2.3-70-g09d2