Commit cb2628ec authored by Kenton Varda's avatar Kenton Varda

Initialize HTTP test cases on first use to work around MSVC initialization ordering.

parent 01917db9
...@@ -555,13 +555,14 @@ void testHttpServerRequest(kj::AsyncIoContext& io, ...@@ -555,13 +555,14 @@ void testHttpServerRequest(kj::AsyncIoContext& io,
KJ_EXPECT(service.getRequestCount() == 1); KJ_EXPECT(service.getRequestCount() == 1);
} }
auto HUGE_STRING = kj::strArray(kj::repeat("abcdefgh", 4096), ""); kj::ArrayPtr<const HttpRequestTestCase> requestTestCases() {
auto HUGE_REQUEST = kj::str( static const auto HUGE_STRING = kj::strArray(kj::repeat("abcdefgh", 4096), "");
static const auto HUGE_REQUEST = kj::str(
"GET / HTTP/1.1\r\n" "GET / HTTP/1.1\r\n"
"Host: ", HUGE_STRING, "\r\n" "Host: ", HUGE_STRING, "\r\n"
"\r\n"); "\r\n");
static const HttpRequestTestCase REQUEST_TEST_CASES[] { static const HttpRequestTestCase REQUEST_TEST_CASES[] {
{ {
"GET /foo/bar HTTP/1.1\r\n" "GET /foo/bar HTTP/1.1\r\n"
"Host: example.com\r\n" "Host: example.com\r\n"
...@@ -651,9 +652,13 @@ static const HttpRequestTestCase REQUEST_TEST_CASES[] { ...@@ -651,9 +652,13 @@ static const HttpRequestTestCase REQUEST_TEST_CASES[] {
{{HttpHeaderId::HOST, HUGE_STRING}}, {{HttpHeaderId::HOST, HUGE_STRING}},
nullptr, {} nullptr, {}
}, },
}; };
return REQUEST_TEST_CASES;
}
static const HttpResponseTestCase RESPONSE_TEST_CASES[] { kj::ArrayPtr<const HttpResponseTestCase> responseTestCases() {
static const HttpResponseTestCase RESPONSE_TEST_CASES[] {
{ {
"HTTP/1.1 200 OK\r\n" "HTTP/1.1 200 OK\r\n"
"Content-Type: text/plain\r\n" "Content-Type: text/plain\r\n"
...@@ -710,12 +715,15 @@ static const HttpResponseTestCase RESPONSE_TEST_CASES[] { ...@@ -710,12 +715,15 @@ static const HttpResponseTestCase RESPONSE_TEST_CASES[] {
{{HttpHeaderId::CONTENT_TYPE, "text/plain"}}, {{HttpHeaderId::CONTENT_TYPE, "text/plain"}},
nullptr, { "qux", "corge" } nullptr, { "qux", "corge" }
}, },
}; };
return RESPONSE_TEST_CASES;
}
KJ_TEST("HttpClient requests") { KJ_TEST("HttpClient requests") {
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
for (auto& testCase: REQUEST_TEST_CASES) { for (auto& testCase: requestTestCases()) {
if (testCase.side == SERVER_ONLY) continue; if (testCase.side == SERVER_ONLY) continue;
KJ_CONTEXT(testCase.raw); KJ_CONTEXT(testCase.raw);
testHttpClientRequest(io, testCase); testHttpClientRequest(io, testCase);
...@@ -726,7 +734,7 @@ KJ_TEST("HttpClient responses") { ...@@ -726,7 +734,7 @@ KJ_TEST("HttpClient responses") {
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
size_t FRAGMENT_SIZES[] = { 1, 2, 3, 4, 5, 6, 7, 8, 16, 31, kj::maxValue }; size_t FRAGMENT_SIZES[] = { 1, 2, 3, 4, 5, 6, 7, 8, 16, 31, kj::maxValue };
for (auto& testCase: RESPONSE_TEST_CASES) { for (auto& testCase: responseTestCases()) {
if (testCase.side == SERVER_ONLY) continue; if (testCase.side == SERVER_ONLY) continue;
for (size_t fragmentSize: FRAGMENT_SIZES) { for (size_t fragmentSize: FRAGMENT_SIZES) {
KJ_CONTEXT(testCase.raw, fragmentSize); KJ_CONTEXT(testCase.raw, fragmentSize);
...@@ -759,7 +767,7 @@ KJ_TEST("HttpServer requests") { ...@@ -759,7 +767,7 @@ KJ_TEST("HttpServer requests") {
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
for (auto& testCase: REQUEST_TEST_CASES) { for (auto& testCase: requestTestCases()) {
if (testCase.side == CLIENT_ONLY) continue; if (testCase.side == CLIENT_ONLY) continue;
KJ_CONTEXT(testCase.raw); KJ_CONTEXT(testCase.raw);
testHttpServerRequest(io, testCase, testHttpServerRequest(io, testCase,
...@@ -790,7 +798,7 @@ KJ_TEST("HttpServer responses") { ...@@ -790,7 +798,7 @@ KJ_TEST("HttpServer responses") {
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
for (auto& testCase: RESPONSE_TEST_CASES) { for (auto& testCase: responseTestCases()) {
if (testCase.side == CLIENT_ONLY) continue; if (testCase.side == CLIENT_ONLY) continue;
KJ_CONTEXT(testCase.raw); KJ_CONTEXT(testCase.raw);
testHttpServerRequest(io, testHttpServerRequest(io,
...@@ -800,7 +808,8 @@ KJ_TEST("HttpServer responses") { ...@@ -800,7 +808,8 @@ KJ_TEST("HttpServer responses") {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
static const HttpTestCase PIPELINE_TESTS[] = { kj::ArrayPtr<const HttpTestCase> pipelineTestCases() {
static const HttpTestCase PIPELINE_TESTS[] = {
{ {
{ {
"GET / HTTP/1.1\r\n" "GET / HTTP/1.1\r\n"
...@@ -881,9 +890,14 @@ static const HttpTestCase PIPELINE_TESTS[] = { ...@@ -881,9 +890,14 @@ static const HttpTestCase PIPELINE_TESTS[] = {
200, "OK", {}, 7, { "foo bar" } 200, "OK", {}, 7, { "foo bar" }
}, },
}, },
}; };
return PIPELINE_TESTS;
}
KJ_TEST("HttpClient pipeline") { KJ_TEST("HttpClient pipeline") {
auto PIPELINE_TESTS = pipelineTestCases();
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
auto pipe = io.provider->newTwoWayPipe(); auto pipe = io.provider->newTwoWayPipe();
...@@ -933,6 +947,8 @@ KJ_TEST("HttpClient pipeline") { ...@@ -933,6 +947,8 @@ KJ_TEST("HttpClient pipeline") {
} }
KJ_TEST("HttpClient parallel pipeline") { KJ_TEST("HttpClient parallel pipeline") {
auto PIPELINE_TESTS = pipelineTestCases();
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
auto pipe = io.provider->newTwoWayPipe(); auto pipe = io.provider->newTwoWayPipe();
...@@ -986,6 +1002,8 @@ KJ_TEST("HttpClient parallel pipeline") { ...@@ -986,6 +1002,8 @@ KJ_TEST("HttpClient parallel pipeline") {
} }
KJ_TEST("HttpServer pipeline") { KJ_TEST("HttpServer pipeline") {
auto PIPELINE_TESTS = pipelineTestCases();
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
auto pipe = io.provider->newTwoWayPipe(); auto pipe = io.provider->newTwoWayPipe();
...@@ -1011,6 +1029,8 @@ KJ_TEST("HttpServer pipeline") { ...@@ -1011,6 +1029,8 @@ KJ_TEST("HttpServer pipeline") {
} }
KJ_TEST("HttpServer parallel pipeline") { KJ_TEST("HttpServer parallel pipeline") {
auto PIPELINE_TESTS = pipelineTestCases();
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
auto pipe = io.provider->newTwoWayPipe(); auto pipe = io.provider->newTwoWayPipe();
...@@ -1037,6 +1057,8 @@ KJ_TEST("HttpServer parallel pipeline") { ...@@ -1037,6 +1057,8 @@ KJ_TEST("HttpServer parallel pipeline") {
} }
KJ_TEST("HttpClient <-> HttpServer") { KJ_TEST("HttpClient <-> HttpServer") {
auto PIPELINE_TESTS = pipelineTestCases();
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
auto pipe = io.provider->newTwoWayPipe(); auto pipe = io.provider->newTwoWayPipe();
...@@ -1082,6 +1104,8 @@ KJ_TEST("HttpClient <-> HttpServer") { ...@@ -1082,6 +1104,8 @@ KJ_TEST("HttpClient <-> HttpServer") {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
KJ_TEST("HttpServer request timeout") { KJ_TEST("HttpServer request timeout") {
auto PIPELINE_TESTS = pipelineTestCases();
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
auto pipe = io.provider->newTwoWayPipe(); auto pipe = io.provider->newTwoWayPipe();
...@@ -1100,6 +1124,8 @@ KJ_TEST("HttpServer request timeout") { ...@@ -1100,6 +1124,8 @@ KJ_TEST("HttpServer request timeout") {
} }
KJ_TEST("HttpServer pipeline timeout") { KJ_TEST("HttpServer pipeline timeout") {
auto PIPELINE_TESTS = pipelineTestCases();
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
auto pipe = io.provider->newTwoWayPipe(); auto pipe = io.provider->newTwoWayPipe();
...@@ -1146,6 +1172,8 @@ private: ...@@ -1146,6 +1172,8 @@ private:
}; };
KJ_TEST("HttpServer no response") { KJ_TEST("HttpServer no response") {
auto PIPELINE_TESTS = pipelineTestCases();
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
auto pipe = io.provider->newTwoWayPipe(); auto pipe = io.provider->newTwoWayPipe();
...@@ -1170,6 +1198,8 @@ KJ_TEST("HttpServer no response") { ...@@ -1170,6 +1198,8 @@ KJ_TEST("HttpServer no response") {
} }
KJ_TEST("HttpServer disconnected") { KJ_TEST("HttpServer disconnected") {
auto PIPELINE_TESTS = pipelineTestCases();
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
auto pipe = io.provider->newTwoWayPipe(); auto pipe = io.provider->newTwoWayPipe();
...@@ -1188,6 +1218,8 @@ KJ_TEST("HttpServer disconnected") { ...@@ -1188,6 +1218,8 @@ KJ_TEST("HttpServer disconnected") {
} }
KJ_TEST("HttpServer overloaded") { KJ_TEST("HttpServer overloaded") {
auto PIPELINE_TESTS = pipelineTestCases();
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
auto pipe = io.provider->newTwoWayPipe(); auto pipe = io.provider->newTwoWayPipe();
...@@ -1206,6 +1238,8 @@ KJ_TEST("HttpServer overloaded") { ...@@ -1206,6 +1238,8 @@ KJ_TEST("HttpServer overloaded") {
} }
KJ_TEST("HttpServer unimplemented") { KJ_TEST("HttpServer unimplemented") {
auto PIPELINE_TESTS = pipelineTestCases();
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
auto pipe = io.provider->newTwoWayPipe(); auto pipe = io.provider->newTwoWayPipe();
...@@ -1224,6 +1258,8 @@ KJ_TEST("HttpServer unimplemented") { ...@@ -1224,6 +1258,8 @@ KJ_TEST("HttpServer unimplemented") {
} }
KJ_TEST("HttpServer threw exception") { KJ_TEST("HttpServer threw exception") {
auto PIPELINE_TESTS = pipelineTestCases();
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
auto pipe = io.provider->newTwoWayPipe(); auto pipe = io.provider->newTwoWayPipe();
...@@ -1264,6 +1300,8 @@ private: ...@@ -1264,6 +1300,8 @@ private:
}; };
KJ_TEST("HttpServer threw exception after starting response") { KJ_TEST("HttpServer threw exception after starting response") {
auto PIPELINE_TESTS = pipelineTestCases();
auto io = kj::setupAsyncIo(); auto io = kj::setupAsyncIo();
auto pipe = io.provider->newTwoWayPipe(); auto pipe = io.provider->newTwoWayPipe();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment