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
|
// 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>
namespace zen::tests::hub {
using namespace std::literals;
TEST_SUITE_BEGIN("hub.lifecycle");
TEST_CASE("hub.lifecycle.basic")
{
{
ZenServerInstance Instance(TestEnv, ZenServerInstance::ServerMode::kHubServer);
const uint16_t PortNumber = Instance.SpawnServerAndWaitUntilReady();
CHECK(PortNumber != 0);
HttpClient Client(Instance.GetBaseUri() + "/hub/");
HttpClient::Response Result = Client.Get("status");
CHECK(Result);
}
}
TEST_CASE("hub.lifecycle.children")
{
ZenServerInstance Instance(TestEnv, ZenServerInstance::ServerMode::kHubServer);
const uint16_t PortNumber = Instance.SpawnServerAndWaitUntilReady();
REQUIRE(PortNumber != 0);
SUBCASE("spawn")
{
HttpClient Client(Instance.GetBaseUri() + "/hub/");
HttpClient::Response Result = Client.Get("status");
REQUIRE(Result);
{
Result = Client.Post("modules/abc/provision");
REQUIRE(Result);
CbObject AbcResult = Result.AsObject();
CHECK(AbcResult["moduleId"].AsString() == "abc"sv);
const uint16_t AbcPort = AbcResult["port"].AsUInt16(0);
CHECK_NE(AbcPort, 0);
// This should be a fresh instance with no contents
HttpClient AbcClient(fmt::format("http://localhost:{}", AbcPort));
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);
const uint16_t 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));
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);
Result = Client.Post("modules/def/deprovision");
REQUIRE(Result);
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);
const uint16_t 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));
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);
const uint16_t 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));
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);
Result = Client.Post("modules/def/deprovision");
REQUIRE(Result);
// 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);
const uint16_t 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));
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);
const uint16_t 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));
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);
Result = Client.Post("modules/def/deprovision");
REQUIRE(Result);
// final sanity check that the hub is still responsive
Result = Client.Get("status");
CHECK(Result);
}
}
TEST_SUITE_END();
TEST_CASE("hub.consul.lifecycle")
{
zen::consul::ConsulProcess ConsulProc;
ConsulProc.SpawnConsulAgent();
zen::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();
}
} // namespace zen::tests::hub
#endif
|