aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver-test/hub-tests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenserver-test/hub-tests.cpp')
-rw-r--r--src/zenserver-test/hub-tests.cpp58
1 files changed, 46 insertions, 12 deletions
diff --git a/src/zenserver-test/hub-tests.cpp b/src/zenserver-test/hub-tests.cpp
index b2da552fc..9d1ee44fb 100644
--- a/src/zenserver-test/hub-tests.cpp
+++ b/src/zenserver-test/hub-tests.cpp
@@ -329,17 +329,36 @@ TEST_CASE("hub.lifecycle.children")
CHECK_EQ(Result.AsText(), "GhijklmNop"sv);
}
- Result = Client.Post("modules/abc/deprovision");
+ // Deprovision all modules at once
+ Result = Client.Post("deprovision");
REQUIRE(Result);
+ CHECK_EQ(Result.StatusCode, HttpResponseCode::Accepted);
+ {
+ CbObject Body = Result.AsObject();
+ CbArrayView AcceptedArr = Body["Accepted"].AsArrayView();
+ CHECK_EQ(AcceptedArr.Num(), 2u);
+ bool FoundAbc = false;
+ bool FoundDef = false;
+ for (CbFieldView F : AcceptedArr)
+ {
+ if (F.AsString() == "abc"sv)
+ {
+ FoundAbc = true;
+ }
+ else if (F.AsString() == "def"sv)
+ {
+ FoundDef = true;
+ }
+ }
+ CHECK(FoundAbc);
+ CHECK(FoundDef);
+ }
REQUIRE(WaitForModuleGone(Client, "abc"));
+ REQUIRE(WaitForModuleGone(Client, "def"));
{
HttpClient ModClient(fmt::format("http://localhost:{}", AbcPort), kFastTimeout);
CHECK(WaitForPortUnreachable(ModClient));
}
-
- Result = Client.Post("modules/def/deprovision");
- REQUIRE(Result);
- REQUIRE(WaitForModuleGone(Client, "def"));
{
HttpClient ModClient(fmt::format("http://localhost:{}", DefPort), kFastTimeout);
CHECK(WaitForPortUnreachable(ModClient));
@@ -349,6 +368,19 @@ TEST_CASE("hub.lifecycle.children")
Result = Client.Get("status");
REQUIRE(Result);
CHECK_EQ(Result.AsObject()["modules"].AsArrayView().Num(), 0u);
+
+ // Deprovision-all with no modules
+ Result = Client.Post("deprovision");
+ CHECK(Result);
+}
+
+// Local agent talks on loopback but can still be slow on shared CI runners
+// (macOS in particular). Override ConsulClient's short production-default
+// timeouts so tests don't flake on first-call latency.
+static consul::ConsulClient::Configuration
+MakeTestConsulClientConfig()
+{
+ return {.BaseUri = "http://localhost:8500/", .ConnectTimeout = std::chrono::seconds{5}, .Timeout = std::chrono::seconds{5}};
}
static bool
@@ -377,7 +409,7 @@ TEST_CASE("hub.consul.kv")
consul::ConsulProcess ConsulProc;
ConsulProc.SpawnConsulAgent();
- consul::ConsulClient Client("http://localhost:8500/");
+ consul::ConsulClient Client(MakeTestConsulClientConfig());
Client.SetKeyValue("zen/hub/testkey", "testvalue");
std::string RetrievedValue = Client.GetKeyValue("zen/hub/testkey");
@@ -399,7 +431,7 @@ TEST_CASE("hub.consul.hub.registration")
"--consul-health-interval-seconds=5 --consul-deregister-after-seconds=60");
REQUIRE(PortNumber != 0);
- consul::ConsulClient Client("http://localhost:8500/");
+ consul::ConsulClient Client(MakeTestConsulClientConfig());
REQUIRE(WaitForConsulService(Client, "zen-hub-test-instance", true, 5000));
// Verify custom intervals flowed through to the registered check
@@ -480,7 +512,7 @@ TEST_CASE("hub.consul.hub.registration.token")
// Use a plain client -- dev-mode Consul doesn't enforce ACLs, but the
// server has exercised the ConsulTokenEnv -> GetEnvVariable -> ConsulClient path.
- consul::ConsulClient Client("http://localhost:8500/");
+ consul::ConsulClient Client(MakeTestConsulClientConfig());
REQUIRE(WaitForConsulService(Client, "zen-hub-test-instance", true, 5000));
@@ -501,7 +533,7 @@ TEST_CASE("hub.consul.provision.registration")
Instance.SpawnServerAndWaitUntilReady("--consul-endpoint=http://localhost:8500/ --instance-id=test-instance");
REQUIRE(PortNumber != 0);
- consul::ConsulClient Client("http://localhost:8500/");
+ consul::ConsulClient Client(MakeTestConsulClientConfig());
REQUIRE(WaitForConsulService(Client, "zen-hub-test-instance", true, 5000));
@@ -640,10 +672,11 @@ TEST_CASE("hub.consul.provision.registration")
Result = HubClient.Post("modules/testmod/deprovision");
REQUIRE(Result);
REQUIRE(WaitForConsulService(Client, "testmod", false, 10000));
+ REQUIRE(WaitForModuleGone(HubClient, "testmod"));
{
HttpClient ModClient(fmt::format("http://localhost:{}", ModulePort), kFastTimeout);
- CHECK(!ModClient.Get("/health/"));
+ CHECK(WaitForPortUnreachable(ModClient));
}
}
@@ -762,9 +795,10 @@ TEST_CASE("hub.hibernate.errors")
CHECK(!Result);
CHECK_EQ(Result.StatusCode, HttpResponseCode::NotFound);
+ // Obliterate of an unknown module succeeds (cleans up backend data for dehydrated modules)
Result = Client.Delete("modules/unknown");
- CHECK(!Result);
- CHECK_EQ(Result.StatusCode, HttpResponseCode::NotFound);
+ CHECK(Result);
+ CHECK_EQ(Result.StatusCode, HttpResponseCode::Accepted);
// Double-provision: second call while first is in-flight returns 202 Accepted with the same port.
Result = Client.Post("modules/errmod/provision");