1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
|
// Copyright Epic Games, Inc. All Rights Reserved.
#if ZEN_WITH_TESTS
# include "zenserver-test.h"
# include <zencore/testing.h>
# include <zencore/testutils.h>
# include <zencore/workthreadpool.h>
# include <zencore/compactbinarybuilder.h>
# include <zencore/compactbinarypackage.h>
# include <zencore/compress.h>
# include <zencore/filesystem.h>
# include <zencore/stream.h>
# include <zencore/string.h>
# include <zencore/fmtutils.h>
# include <zencore/scopeguard.h>
# include <zenhttp/packageformat.h>
# include <zenremotestore/builds/buildstoragecache.h>
# include <zenutil/workerpools.h>
# include <zenutil/zenserverprocess.h>
# include <zenhttp/httpclient.h>
# include <zenutil/consul.h>
# include <zencore/thread.h>
# include <zencore/timer.h>
# if ZEN_PLATFORM_WINDOWS
# include <zencore/windows.h>
# else
# include <cstdlib>
# endif
namespace zen::tests::hub {
using namespace std::literals;
static const HttpClientSettings kFastTimeout{.ConnectTimeout = std::chrono::milliseconds(200)};
TEST_SUITE_BEGIN("server.hub");
TEST_CASE("hub.lifecycle.children")
{
ZenServerInstance Instance(TestEnv, ZenServerInstance::ServerMode::kHubServer);
const uint16_t PortNumber = Instance.SpawnServerAndWaitUntilReady("--hub-instance-corelimit=2 --hub-instance-http-threads=6");
REQUIRE(PortNumber != 0);
HttpClient Client(Instance.GetBaseUri() + "/hub/", kFastTimeout);
// Verify the hub starts with no modules
{
HttpClient::Response Result = Client.Get("status");
REQUIRE(Result);
CHECK_EQ(Result.AsObject()["modules"].AsArrayView().Num(), 0u);
}
HttpClient::Response Result;
uint16_t AbcPort = 0;
uint16_t DefPort = 0;
{
Result = Client.Post("modules/abc/provision");
REQUIRE(Result);
CbObject AbcResult = Result.AsObject();
CHECK(AbcResult["moduleId"].AsString() == "abc"sv);
AbcPort = AbcResult["port"].AsUInt16(0);
CHECK_NE(AbcPort, 0);
Result = Client.Get("modules/abc");
REQUIRE(Result);
CHECK_EQ(Result.AsObject()["state"].AsString(), "provisioned"sv);
// This should be a fresh instance with no contents
HttpClient AbcClient(fmt::format("http://localhost:{}", AbcPort), kFastTimeout);
CHECK(AbcClient.Get("/health/"));
Result = AbcClient.Get("/z$/ns1/b/0123456789abcdef0123456789abcdef01234567");
CHECK_EQ(Result.StatusCode, HttpResponseCode::NotFound);
Result = AbcClient.Put("/z$/ns1/b/0123456789abcdef0123456789abcdef01234567",
IoBufferBuilder::MakeFromMemory(MakeMemoryView("abcdef"sv)));
CHECK_EQ(Result.StatusCode, HttpResponseCode::Created);
}
{
Result = Client.Post("modules/def/provision");
REQUIRE(Result);
CbObject DefResult = Result.AsObject();
CHECK(DefResult["moduleId"].AsString() == "def"sv);
DefPort = DefResult["port"].AsUInt16(0);
REQUIRE_NE(DefPort, 0);
// This should be a fresh instance with no contents
HttpClient DefClient(fmt::format("http://localhost:{}", DefPort), kFastTimeout);
CHECK(DefClient.Get("/health/"));
Result = DefClient.Get("/z$/ns1/b/0123456789abcdef0123456789abcdef01234567");
CHECK_EQ(Result.StatusCode, HttpResponseCode::NotFound);
Result = DefClient.Put("/z$/ns1/b/0123456789abcdef0123456789abcdef01234567",
IoBufferBuilder::MakeFromMemory(MakeMemoryView("AbcDef"sv)));
CHECK_EQ(Result.StatusCode, HttpResponseCode::Created);
}
// this should be rejected because of the invalid module id
Result = Client.Post("modules/!!!!!/provision");
CHECK(!Result);
Result = Client.Post("modules/ghi/provision");
REQUIRE(Result);
// Tear down instances
Result = Client.Post("modules/abc/deprovision");
REQUIRE(Result);
{
HttpClient ModClient(fmt::format("http://localhost:{}", AbcPort), kFastTimeout);
CHECK(!ModClient.Get("/health/"));
}
Result = Client.Post("modules/def/deprovision");
REQUIRE(Result);
{
HttpClient ModClient(fmt::format("http://localhost:{}", DefPort), kFastTimeout);
CHECK(!ModClient.Get("/health/"));
}
Result = Client.Post("modules/ghi/deprovision");
REQUIRE(Result);
// re-provision to verify that (de)hydration preserved state
{
Result = Client.Post("modules/abc/provision");
REQUIRE(Result);
CbObject AbcResult = Result.AsObject();
CHECK(AbcResult["moduleId"].AsString() == "abc"sv);
AbcPort = AbcResult["port"].AsUInt16(0);
REQUIRE_NE(AbcPort, 0);
// This should contain the content from the previous run
HttpClient AbcClient(fmt::format("http://localhost:{}", AbcPort), kFastTimeout);
CHECK(AbcClient.Get("/health/"));
Result = AbcClient.Get("/z$/ns1/b/0123456789abcdef0123456789abcdef01234567");
CHECK_EQ(Result.StatusCode, HttpResponseCode::OK);
CHECK_EQ(Result.AsText(), "abcdef"sv);
Result = AbcClient.Put("/z$/ns1/b/1123456789abcdef0123456789abcdef01234567",
IoBufferBuilder::MakeFromMemory(MakeMemoryView("ghijklmnop"sv)));
CHECK_EQ(Result.StatusCode, HttpResponseCode::Created);
}
{
Result = Client.Post("modules/def/provision");
REQUIRE(Result);
CbObject DefResult = Result.AsObject();
CHECK(DefResult["moduleId"].AsString() == "def"sv);
DefPort = DefResult["port"].AsUInt16(0);
REQUIRE_NE(DefPort, 0);
// This should contain the content from the previous run
HttpClient DefClient(fmt::format("http://localhost:{}", DefPort), kFastTimeout);
CHECK(DefClient.Get("/health/"));
Result = DefClient.Get("/z$/ns1/b/0123456789abcdef0123456789abcdef01234567");
CHECK_EQ(Result.StatusCode, HttpResponseCode::OK);
CHECK_EQ(Result.AsText(), "AbcDef"sv);
Result = DefClient.Put("/z$/ns1/b/1123456789abcdef0123456789abcdef01234567",
IoBufferBuilder::MakeFromMemory(MakeMemoryView("GhijklmNop"sv)));
CHECK_EQ(Result.StatusCode, HttpResponseCode::Created);
}
Result = Client.Post("modules/abc/deprovision");
REQUIRE(Result);
{
HttpClient ModClient(fmt::format("http://localhost:{}", AbcPort), kFastTimeout);
CHECK(!ModClient.Get("/health/"));
}
Result = Client.Post("modules/def/deprovision");
REQUIRE(Result);
{
HttpClient ModClient(fmt::format("http://localhost:{}", DefPort), kFastTimeout);
CHECK(!ModClient.Get("/health/"));
}
// re-provision to verify that (de)hydration preserved state, including
// state which was generated after the very first dehydration
{
Result = Client.Post("modules/abc/provision");
REQUIRE(Result);
CbObject AbcResult = Result.AsObject();
CHECK(AbcResult["moduleId"].AsString() == "abc"sv);
AbcPort = AbcResult["port"].AsUInt16(0);
REQUIRE_NE(AbcPort, 0);
// This should contain the content from the previous two runs
HttpClient AbcClient(fmt::format("http://localhost:{}", AbcPort), kFastTimeout);
CHECK(AbcClient.Get("/health/"));
Result = AbcClient.Get("/z$/ns1/b/0123456789abcdef0123456789abcdef01234567");
CHECK_EQ(Result.StatusCode, HttpResponseCode::OK);
CHECK_EQ(Result.AsText(), "abcdef"sv);
Result = AbcClient.Get("/z$/ns1/b/1123456789abcdef0123456789abcdef01234567");
CHECK_EQ(Result.StatusCode, HttpResponseCode::OK);
CHECK_EQ(Result.AsText(), "ghijklmnop"sv);
}
{
Result = Client.Post("modules/def/provision");
REQUIRE(Result);
CbObject DefResult = Result.AsObject();
REQUIRE(DefResult["moduleId"].AsString() == "def"sv);
DefPort = DefResult["port"].AsUInt16(0);
REQUIRE_NE(DefPort, 0);
// This should contain the content from the previous two runs
HttpClient DefClient(fmt::format("http://localhost:{}", DefPort), kFastTimeout);
CHECK(DefClient.Get("/health/"));
Result = DefClient.Get("/z$/ns1/b/0123456789abcdef0123456789abcdef01234567");
CHECK_EQ(Result.StatusCode, HttpResponseCode::OK);
CHECK_EQ(Result.AsText(), "AbcDef"sv);
Result = DefClient.Get("/z$/ns1/b/1123456789abcdef0123456789abcdef01234567");
CHECK_EQ(Result.StatusCode, HttpResponseCode::OK);
CHECK_EQ(Result.AsText(), "GhijklmNop"sv);
}
Result = Client.Post("modules/abc/deprovision");
REQUIRE(Result);
{
HttpClient ModClient(fmt::format("http://localhost:{}", AbcPort), kFastTimeout);
CHECK(!ModClient.Get("/health/"));
}
Result = Client.Post("modules/def/deprovision");
REQUIRE(Result);
{
HttpClient ModClient(fmt::format("http://localhost:{}", DefPort), kFastTimeout);
CHECK(!ModClient.Get("/health/"));
}
// final sanity check that the hub is still responsive and all modules are gone
Result = Client.Get("status");
REQUIRE(Result);
CHECK_EQ(Result.AsObject()["modules"].AsArrayView().Num(), 0u);
}
static bool
WaitForConsulService(consul::ConsulClient& Client, std::string_view ServiceId, bool ExpectedState, int TimeoutMs)
{
Stopwatch Timer;
uint64_t Index = 0;
while (Timer.GetElapsedTimeMs() < static_cast<uint64_t>(TimeoutMs))
{
uint64_t RemainingMs = static_cast<uint64_t>(TimeoutMs) - Timer.GetElapsedTimeMs();
int WaitSeconds = std::max(1, static_cast<int>(RemainingMs / 1000));
if (Client.WatchService(ServiceId, Index, WaitSeconds) == ExpectedState)
{
return true;
}
if (Index == 0)
{
Sleep(100); // error path only: avoid tight loop on persistent connection failure
}
}
return Client.HasService(ServiceId) == ExpectedState;
}
TEST_CASE("hub.consul.kv")
{
consul::ConsulProcess ConsulProc;
ConsulProc.SpawnConsulAgent();
consul::ConsulClient Client("http://localhost:8500/");
Client.SetKeyValue("zen/hub/testkey", "testvalue");
std::string RetrievedValue = Client.GetKeyValue("zen/hub/testkey");
CHECK_EQ(RetrievedValue, "testvalue");
Client.DeleteKey("zen/hub/testkey");
ConsulProc.StopConsulAgent();
}
TEST_CASE("hub.consul.hub.registration")
{
consul::ConsulProcess ConsulProc;
ConsulProc.SpawnConsulAgent();
ZenServerInstance Instance(TestEnv, ZenServerInstance::ServerMode::kHubServer);
const uint16_t PortNumber =
Instance.SpawnServerAndWaitUntilReady("--consul-endpoint=http://localhost:8500/ --instance-id=test-instance");
REQUIRE(PortNumber != 0);
consul::ConsulClient Client("http://localhost:8500/");
REQUIRE(WaitForConsulService(Client, "zen-hub-test-instance", true, 5000));
Instance.Shutdown();
CHECK(!Client.HasService("zen-hub-test-instance"));
ConsulProc.StopConsulAgent();
}
TEST_CASE("hub.consul.hub.registration.token")
{
// Set an env var that the server will read its Consul token from.
// Children inherit parent environment, so the spawned server will see it.
constexpr const char* TokenEnvVarName = "ZEN_TEST_CONSUL_TOKEN";
constexpr const char* TokenValue = "test-token-value";
# if ZEN_PLATFORM_WINDOWS
char PrevBuf[1024] = {};
DWORD PrevLen = GetEnvironmentVariableA(TokenEnvVarName, PrevBuf, sizeof(PrevBuf));
REQUIRE(PrevLen < sizeof(PrevBuf));
SetEnvironmentVariableA(TokenEnvVarName, TokenValue);
auto EnvCleanup = MakeGuard([PrevEnvValue = std::string(PrevBuf, PrevLen), HadPrevToken = PrevLen > 0] {
SetEnvironmentVariableA(TokenEnvVarName, HadPrevToken ? PrevEnvValue.c_str() : nullptr);
});
# else
const char* PrevEnvPtr = getenv(TokenEnvVarName);
setenv(TokenEnvVarName, TokenValue, /*overwrite=*/1);
auto EnvCleanup = MakeGuard([PrevEnvValue = std::string(PrevEnvPtr ? PrevEnvPtr : ""), HadPrevToken = PrevEnvPtr != nullptr] {
if (HadPrevToken)
{
setenv(TokenEnvVarName, PrevEnvValue.c_str(), /*overwrite=*/1);
}
else
{
unsetenv(TokenEnvVarName);
}
});
# endif
consul::ConsulProcess ConsulProc;
ConsulProc.SpawnConsulAgent();
ZenServerInstance Instance(TestEnv, ZenServerInstance::ServerMode::kHubServer);
const uint16_t PortNumber = Instance.SpawnServerAndWaitUntilReady(
"--consul-endpoint=http://localhost:8500/ --instance-id=test-instance "
"--consul-token-env=ZEN_TEST_CONSUL_TOKEN");
REQUIRE(PortNumber != 0);
// 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/");
REQUIRE(WaitForConsulService(Client, "zen-hub-test-instance", true, 5000));
Instance.Shutdown();
CHECK(!Client.HasService("zen-hub-test-instance"));
ConsulProc.StopConsulAgent();
}
TEST_CASE("hub.consul.provision.registration")
{
consul::ConsulProcess ConsulProc;
ConsulProc.SpawnConsulAgent();
ZenServerInstance Instance(TestEnv, ZenServerInstance::ServerMode::kHubServer);
const uint16_t PortNumber =
Instance.SpawnServerAndWaitUntilReady("--consul-endpoint=http://localhost:8500/ --instance-id=test-instance");
REQUIRE(PortNumber != 0);
consul::ConsulClient Client("http://localhost:8500/");
REQUIRE(WaitForConsulService(Client, "zen-hub-test-instance", true, 5000));
HttpClient HubClient(Instance.GetBaseUri() + "/hub/", kFastTimeout);
HttpClient::Response Result = HubClient.Post("modules/testmod/provision");
REQUIRE(Result);
CHECK(Client.HasService("testmod"));
{
const uint16_t ModulePort = Result.AsObject()["port"].AsUInt16(0);
REQUIRE(ModulePort != 0);
{
HttpClient ModClient(fmt::format("http://localhost:{}", ModulePort), kFastTimeout);
CHECK(ModClient.Get("/health/"));
}
std::string JsonError;
CbFieldIterator ServicesRoot = LoadCompactBinaryFromJson(Client.GetAgentServicesJson(), JsonError);
REQUIRE(JsonError.empty());
CbObjectView ServicesMap;
for (CbFieldView F : ServicesRoot)
{
if (F.IsObject())
{
ServicesMap = F.AsObjectView();
}
}
REQUIRE(ServicesMap);
// Verify fields registered by OnProvisioned
{
CbObjectView ModService = ServicesMap["testmod"].AsObjectView();
CHECK_EQ(ModService["ID"sv].AsString(), "testmod"sv);
CHECK_EQ(ModService["Service"sv].AsString(), "zen-storage"sv);
CHECK_EQ(ModService["Port"sv].AsDouble(0), double(ModulePort));
bool FoundModuleTag = false;
bool FoundHubTag = false;
bool FoundVersionTag = false;
for (CbFieldView Tag : ModService["Tags"].AsArrayView())
{
std::string_view TagStr = Tag.AsString();
if (TagStr == "module:testmod"sv)
{
FoundModuleTag = true;
}
else if (TagStr == "zen-hub:zen-hub-test-instance"sv)
{
FoundHubTag = true;
}
else if (TagStr.substr(0, 8) == "version:"sv)
{
FoundVersionTag = true;
}
}
CHECK(FoundModuleTag);
CHECK(FoundHubTag);
CHECK(FoundVersionTag);
}
// Verify fields registered by InitializeConsulRegistration
{
CbObjectView HubService = ServicesMap["zen-hub-test-instance"].AsObjectView();
CHECK_EQ(HubService["ID"sv].AsString(), "zen-hub-test-instance"sv);
CHECK_EQ(HubService["Service"sv].AsString(), "zen-hub"sv);
CHECK_EQ(HubService["Port"sv].AsDouble(0), double(PortNumber));
}
Result = HubClient.Post("modules/testmod/deprovision");
REQUIRE(Result);
{
HttpClient ModClient(fmt::format("http://localhost:{}", ModulePort), kFastTimeout);
CHECK(!ModClient.Get("/health/"));
}
}
CHECK(!Client.HasService("testmod"));
Instance.Shutdown();
ConsulProc.StopConsulAgent();
}
TEST_CASE("hub.hibernate.lifecycle")
{
ZenServerInstance Instance(TestEnv, ZenServerInstance::ServerMode::kHubServer);
const uint16_t PortNumber = Instance.SpawnServerAndWaitUntilReady("--hub-instance-corelimit=2 --hub-instance-http-threads=6");
REQUIRE(PortNumber != 0);
HttpClient Client(Instance.GetBaseUri() + "/hub/", kFastTimeout);
// Provision
HttpClient::Response Result = Client.Post("modules/testmod/provision");
REQUIRE(Result);
CHECK_EQ(Result.AsObject()["moduleId"].AsString(), "testmod"sv);
const uint16_t ModulePort = Result.AsObject()["port"].AsUInt16(0);
REQUIRE_NE(ModulePort, 0);
Result = Client.Get("modules/testmod");
REQUIRE(Result);
CHECK_EQ(Result.AsObject()["state"].AsString(), "provisioned"sv);
{
HttpClient ModClient(fmt::format("http://localhost:{}", ModulePort), kFastTimeout);
CHECK(ModClient.Get("/health/"));
// Write data to verify it survives the hibernate/wake cycle
Result = ModClient.Put("/z$/ns1/b/0123456789abcdef0123456789abcdef01234567",
IoBufferBuilder::MakeFromMemory(MakeMemoryView("hibernatetest"sv)));
CHECK_EQ(Result.StatusCode, HttpResponseCode::Created);
}
// Hibernate - state should become "hibernated", server should be unreachable
Result = Client.Post("modules/testmod/hibernate");
REQUIRE(Result);
CHECK_EQ(Result.AsObject()["moduleId"].AsString(), "testmod"sv);
Result = Client.Get("modules/testmod");
REQUIRE(Result);
CHECK_EQ(Result.AsObject()["state"].AsString(), "hibernated"sv);
{
HttpClient ModClient(fmt::format("http://localhost:{}", ModulePort), kFastTimeout);
CHECK(!ModClient.Get("/health/"));
}
// Wake - state should return to "provisioned", server should be reachable, data should be intact
Result = Client.Post("modules/testmod/wake");
REQUIRE(Result);
CHECK_EQ(Result.AsObject()["moduleId"].AsString(), "testmod"sv);
Result = Client.Get("modules/testmod");
REQUIRE(Result);
CHECK_EQ(Result.AsObject()["state"].AsString(), "provisioned"sv);
{
HttpClient ModClient(fmt::format("http://localhost:{}", ModulePort), kFastTimeout);
CHECK(ModClient.Get("/health/"));
Result = ModClient.Get("/z$/ns1/b/0123456789abcdef0123456789abcdef01234567");
CHECK_EQ(Result.StatusCode, HttpResponseCode::OK);
CHECK_EQ(Result.AsText(), "hibernatetest"sv);
}
// Deprovision - server should become unreachable
Result = Client.Post("modules/testmod/deprovision");
REQUIRE(Result);
{
HttpClient ModClient(fmt::format("http://localhost:{}", ModulePort), kFastTimeout);
CHECK(!ModClient.Get("/health/"));
}
// Re-provision - server should be reachable on its (potentially new) port
Result = Client.Post("modules/testmod/provision");
REQUIRE(Result);
CHECK_EQ(Result.AsObject()["moduleId"].AsString(), "testmod"sv);
const uint16_t ModulePort2 = Result.AsObject()["port"].AsUInt16(0);
REQUIRE_NE(ModulePort2, 0);
{
HttpClient ModClient(fmt::format("http://localhost:{}", ModulePort2), kFastTimeout);
CHECK(ModClient.Get("/health/"));
}
// Final deprovision - server should become unreachable
Result = Client.Post("modules/testmod/deprovision");
REQUIRE(Result);
{
HttpClient ModClient(fmt::format("http://localhost:{}", ModulePort2), kFastTimeout);
CHECK(!ModClient.Get("/health/"));
}
}
TEST_CASE("hub.hibernate.errors")
{
ZenServerInstance Instance(TestEnv, ZenServerInstance::ServerMode::kHubServer);
const uint16_t PortNumber = Instance.SpawnServerAndWaitUntilReady("--hub-instance-corelimit=2 --hub-instance-http-threads=6");
REQUIRE(PortNumber != 0);
HttpClient Client(Instance.GetBaseUri() + "/hub/", kFastTimeout);
// Hibernate/wake on an unknown module id should return 404
HttpClient::Response Result = Client.Post("modules/unknown/hibernate");
CHECK(!Result);
CHECK_EQ(Result.StatusCode, HttpResponseCode::NotFound);
Result = Client.Post("modules/unknown/wake");
CHECK(!Result);
CHECK_EQ(Result.StatusCode, HttpResponseCode::NotFound);
// Double-hibernate: first call succeeds, second returns 400 (wrong state)
Result = Client.Post("modules/errmod/provision");
REQUIRE(Result);
Result = Client.Post("modules/errmod/hibernate");
REQUIRE(Result);
Result = Client.Post("modules/errmod/hibernate");
CHECK(!Result);
CHECK_EQ(Result.StatusCode, HttpResponseCode::BadRequest);
// Wake on provisioned: succeeds (state restored), then waking again returns 400
Result = Client.Post("modules/errmod/wake");
REQUIRE(Result);
Result = Client.Post("modules/errmod/wake");
CHECK(!Result);
CHECK_EQ(Result.StatusCode, HttpResponseCode::BadRequest);
}
TEST_SUITE_END();
} // namespace zen::tests::hub
#endif
|