mirror of https://github.com/oxen-io/oxen-mq.git
Test suite: use different ports for each test
Apple, in particular, often fails tests with an address already in use if attempt to reuse a port that the process just closed, because it is a wonderful OS.
This commit is contained in:
parent
8ed529200b
commit
7049d3cb5a
|
@ -6,6 +6,16 @@ using namespace lokimq;
|
||||||
|
|
||||||
static auto startup = std::chrono::steady_clock::now();
|
static auto startup = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
/// Returns a localhost connection string to listen on. It can be considered random, though in
|
||||||
|
/// practice in the current implementation is sequential starting at 4500.
|
||||||
|
inline std::string random_localhost() {
|
||||||
|
static uint16_t last = 4499;
|
||||||
|
last++;
|
||||||
|
assert(last); // We should never call this enough to overflow
|
||||||
|
return "tcp://127.0.0.1:" + std::to_string(last);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Waits up to 100ms for something to happen.
|
/// Waits up to 100ms for something to happen.
|
||||||
template <typename Func>
|
template <typename Func>
|
||||||
inline void wait_for(Func f) {
|
inline void wait_for(Func f) {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
using namespace lokimq;
|
using namespace lokimq;
|
||||||
|
|
||||||
TEST_CASE("basic commands", "[commands]") {
|
TEST_CASE("basic commands", "[commands]") {
|
||||||
std::string listen = "tcp://127.0.0.1:4567";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // generate ephemeral keys
|
||||||
false, // not a service node
|
false, // not a service node
|
||||||
|
@ -76,7 +76,7 @@ TEST_CASE("basic commands", "[commands]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("outgoing auth level", "[commands][auth]") {
|
TEST_CASE("outgoing auth level", "[commands][auth]") {
|
||||||
std::string listen = "tcp://127.0.0.1:4567";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // generate ephemeral keys
|
||||||
false, // not a service node
|
false, // not a service node
|
||||||
|
@ -158,7 +158,7 @@ TEST_CASE("deferred replies on incoming connections", "[commands][hey google]")
|
||||||
// Tests that the ConnectionID from a Message can be stored and reused later to contact the
|
// Tests that the ConnectionID from a Message can be stored and reused later to contact the
|
||||||
// original node.
|
// original node.
|
||||||
|
|
||||||
std::string listen = "tcp://127.0.0.1:4567";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // generate ephemeral keys
|
||||||
false, // not a service node
|
false, // not a service node
|
||||||
|
@ -270,7 +270,7 @@ TEST_CASE("deferred replies on incoming connections", "[commands][hey google]")
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("send failure callbacks", "[commands][queue_full]") {
|
TEST_CASE("send failure callbacks", "[commands][queue_full]") {
|
||||||
std::string listen = "tcp://127.0.0.1:4567";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // generate ephemeral keys
|
||||||
false, // not a service node
|
false, // not a service node
|
||||||
|
@ -364,7 +364,7 @@ TEST_CASE("send failure callbacks", "[commands][queue_full]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("data parts", "[send][data_parts]") {
|
TEST_CASE("data parts", "[send][data_parts]") {
|
||||||
std::string listen = "tcp://127.0.0.1:4567";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // generate ephemeral keys
|
||||||
false, // not a service node
|
false, // not a service node
|
||||||
|
|
|
@ -6,7 +6,7 @@ extern "C" {
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("connections with curve authentication", "[curve][connect]") {
|
TEST_CASE("connections with curve authentication", "[curve][connect]") {
|
||||||
std::string listen = "tcp://127.0.0.1:4455";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // generate ephemeral keys
|
||||||
false, // not a service node
|
false, // not a service node
|
||||||
|
@ -53,16 +53,17 @@ TEST_CASE("self-connection SN optimization", "[connect][self]") {
|
||||||
pubkey.resize(crypto_box_PUBLICKEYBYTES);
|
pubkey.resize(crypto_box_PUBLICKEYBYTES);
|
||||||
privkey.resize(crypto_box_SECRETKEYBYTES);
|
privkey.resize(crypto_box_SECRETKEYBYTES);
|
||||||
REQUIRE(sodium_init() != -1);
|
REQUIRE(sodium_init() != -1);
|
||||||
|
auto listen_addr = random_localhost();
|
||||||
crypto_box_keypair(reinterpret_cast<unsigned char*>(&pubkey[0]), reinterpret_cast<unsigned char*>(&privkey[0]));
|
crypto_box_keypair(reinterpret_cast<unsigned char*>(&pubkey[0]), reinterpret_cast<unsigned char*>(&privkey[0]));
|
||||||
LokiMQ sn{
|
LokiMQ sn{
|
||||||
pubkey, privkey,
|
pubkey, privkey,
|
||||||
true,
|
true,
|
||||||
[&](auto pk) { if (pk == pubkey) return "tcp://127.0.0.1:5544"; else return ""; },
|
[&](auto pk) { if (pk == pubkey) return listen_addr; else return ""s; },
|
||||||
get_logger("S» "),
|
get_logger("S» "),
|
||||||
LogLevel::trace
|
LogLevel::trace
|
||||||
};
|
};
|
||||||
|
|
||||||
sn.listen_curve("tcp://127.0.0.1:5544", [&](auto ip, auto pk, auto sn) {
|
sn.listen_curve(listen_addr, [&](auto ip, auto pk, auto sn) {
|
||||||
auto lock = catch_lock();
|
auto lock = catch_lock();
|
||||||
REQUIRE(ip == "127.0.0.1");
|
REQUIRE(ip == "127.0.0.1");
|
||||||
REQUIRE(sn == (pk == pubkey));
|
REQUIRE(sn == (pk == pubkey));
|
||||||
|
@ -90,7 +91,7 @@ TEST_CASE("self-connection SN optimization", "[connect][self]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("plain-text connections", "[plaintext][connect]") {
|
TEST_CASE("plain-text connections", "[plaintext][connect]") {
|
||||||
std::string listen = "tcp://127.0.0.1:4455";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{get_logger("S» "), LogLevel::trace};
|
LokiMQ server{get_logger("S» "), LogLevel::trace};
|
||||||
|
|
||||||
server.add_category("public", Access{AuthLevel::none});
|
server.add_category("public", Access{AuthLevel::none});
|
||||||
|
@ -129,7 +130,7 @@ TEST_CASE("plain-text connections", "[plaintext][connect]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("unique connection IDs", "[connect][id]") {
|
TEST_CASE("unique connection IDs", "[connect][id]") {
|
||||||
std::string listen = "tcp://127.0.0.1:4455";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{get_logger("S» "), LogLevel::trace};
|
LokiMQ server{get_logger("S» "), LogLevel::trace};
|
||||||
|
|
||||||
ConnectionID first, second;
|
ConnectionID first, second;
|
||||||
|
@ -195,7 +196,7 @@ TEST_CASE("SN disconnections", "[connect][disconnect]") {
|
||||||
pubkey[i].resize(crypto_box_PUBLICKEYBYTES);
|
pubkey[i].resize(crypto_box_PUBLICKEYBYTES);
|
||||||
privkey[i].resize(crypto_box_SECRETKEYBYTES);
|
privkey[i].resize(crypto_box_SECRETKEYBYTES);
|
||||||
crypto_box_keypair(reinterpret_cast<unsigned char*>(&pubkey[i][0]), reinterpret_cast<unsigned char*>(&privkey[i][0]));
|
crypto_box_keypair(reinterpret_cast<unsigned char*>(&pubkey[i][0]), reinterpret_cast<unsigned char*>(&privkey[i][0]));
|
||||||
conn.emplace(pubkey[i], "tcp://127.0.0.1:" + std::to_string(4450 + i));
|
conn.emplace(pubkey[i], random_localhost());
|
||||||
}
|
}
|
||||||
std::atomic<int> his{0};
|
std::atomic<int> his{0};
|
||||||
for (int i = 0; i < pubkey.size(); i++) {
|
for (int i = 0; i < pubkey.size(); i++) {
|
||||||
|
@ -231,7 +232,7 @@ TEST_CASE("SN auth checks", "[sandwich][auth]") {
|
||||||
// isn't recognized as a SN but tries to invoke a SN command it'll be told to disconnect; if it
|
// isn't recognized as a SN but tries to invoke a SN command it'll be told to disconnect; if it
|
||||||
// tries to send again it should reconnect and reauthenticate. This test is meant to test this
|
// tries to send again it should reconnect and reauthenticate. This test is meant to test this
|
||||||
// pattern where the reconnection/reauthentication now authenticates it as a SN.
|
// pattern where the reconnection/reauthentication now authenticates it as a SN.
|
||||||
std::string listen = "tcp://127.0.0.1:4455";
|
std::string listen = random_localhost();
|
||||||
std::string pubkey, privkey;
|
std::string pubkey, privkey;
|
||||||
pubkey.resize(crypto_box_PUBLICKEYBYTES);
|
pubkey.resize(crypto_box_PUBLICKEYBYTES);
|
||||||
privkey.resize(crypto_box_SECRETKEYBYTES);
|
privkey.resize(crypto_box_SECRETKEYBYTES);
|
||||||
|
@ -350,7 +351,7 @@ TEST_CASE("SN auth checks", "[sandwich][auth]") {
|
||||||
TEST_CASE("SN single worker test", "[connect][worker]") {
|
TEST_CASE("SN single worker test", "[connect][worker]") {
|
||||||
// Tests a failure case that could trigger when all workers are allocated (here we make that
|
// Tests a failure case that could trigger when all workers are allocated (here we make that
|
||||||
// simpler by just having one worker).
|
// simpler by just having one worker).
|
||||||
std::string listen = "tcp://127.0.0.1:4455";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "",
|
"", "",
|
||||||
false, // service node
|
false, // service node
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
using namespace lokimq;
|
using namespace lokimq;
|
||||||
|
|
||||||
TEST_CASE("failure responses - UNKNOWNCOMMAND", "[failure][UNKNOWNCOMMAND]") {
|
TEST_CASE("failure responses - UNKNOWNCOMMAND", "[failure][UNKNOWNCOMMAND]") {
|
||||||
std::string listen = "tcp://127.0.0.1:4567";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // generate ephemeral keys
|
||||||
false, // not a service node
|
false, // not a service node
|
||||||
|
@ -47,7 +47,7 @@ TEST_CASE("failure responses - UNKNOWNCOMMAND", "[failure][UNKNOWNCOMMAND]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("failure responses - NO_REPLY_TAG", "[failure][NO_REPLY_TAG]") {
|
TEST_CASE("failure responses - NO_REPLY_TAG", "[failure][NO_REPLY_TAG]") {
|
||||||
std::string listen = "tcp://127.0.0.1:4567";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // generate ephemeral keys
|
||||||
false, // not a service node
|
false, // not a service node
|
||||||
|
@ -108,7 +108,7 @@ TEST_CASE("failure responses - NO_REPLY_TAG", "[failure][NO_REPLY_TAG]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("failure responses - FORBIDDEN", "[failure][FORBIDDEN]") {
|
TEST_CASE("failure responses - FORBIDDEN", "[failure][FORBIDDEN]") {
|
||||||
std::string listen = "tcp://127.0.0.1:4567";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // generate ephemeral keys
|
||||||
false, // not a service node
|
false, // not a service node
|
||||||
|
@ -191,7 +191,7 @@ TEST_CASE("failure responses - FORBIDDEN", "[failure][FORBIDDEN]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("failure responses - NOT_A_SERVICE_NODE", "[failure][NOT_A_SERVICE_NODE]") {
|
TEST_CASE("failure responses - NOT_A_SERVICE_NODE", "[failure][NOT_A_SERVICE_NODE]") {
|
||||||
std::string listen = "tcp://127.0.0.1:4567";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // generate ephemeral keys
|
||||||
false, // not a service node
|
false, // not a service node
|
||||||
|
@ -258,7 +258,7 @@ TEST_CASE("failure responses - NOT_A_SERVICE_NODE", "[failure][NOT_A_SERVICE_NOD
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("failure responses - FORBIDDEN_SN", "[failure][FORBIDDEN_SN]") {
|
TEST_CASE("failure responses - FORBIDDEN_SN", "[failure][FORBIDDEN_SN]") {
|
||||||
std::string listen = "tcp://127.0.0.1:4567";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // generate ephemeral keys
|
||||||
false, // not a service node
|
false, // not a service node
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
using namespace lokimq;
|
using namespace lokimq;
|
||||||
|
|
||||||
TEST_CASE("injected external commands", "[injected]") {
|
TEST_CASE("injected external commands", "[injected]") {
|
||||||
std::string listen = "tcp://127.0.0.1:4567";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // generate ephemeral keys
|
||||||
false, // not a service node
|
false, // not a service node
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
using namespace lokimq;
|
using namespace lokimq;
|
||||||
|
|
||||||
TEST_CASE("basic requests", "[requests]") {
|
TEST_CASE("basic requests", "[requests]") {
|
||||||
std::string listen = "tcp://127.0.0.1:5678";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // generate ephemeral keys
|
||||||
false, // not a service node
|
false, // not a service node
|
||||||
|
@ -61,7 +61,7 @@ TEST_CASE("basic requests", "[requests]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("request from server to client", "[requests]") {
|
TEST_CASE("request from server to client", "[requests]") {
|
||||||
std::string listen = "tcp://127.0.0.1:5678";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // generate ephemeral keys
|
||||||
false, // not a service node
|
false, // not a service node
|
||||||
|
@ -124,7 +124,7 @@ TEST_CASE("request from server to client", "[requests]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("request timeouts", "[requests][timeout]") {
|
TEST_CASE("request timeouts", "[requests][timeout]") {
|
||||||
std::string listen = "tcp://127.0.0.1:5678";
|
std::string listen = random_localhost();
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // generate ephemeral keys
|
||||||
false, // not a service node
|
false, // not a service node
|
||||||
|
|
Loading…
Reference in New Issue