Commit 9d764566 authored by Kenton Varda's avatar Kenton Varda

Fix HTTP pipeline tests to actually wait for each request before sending mock response.

Otherwise, the HTTP client might be destroyed before it has written all data, since the responses have already been received.

In particular this fixes http-test on Win32.
parent e75e853b
......@@ -887,14 +887,15 @@ KJ_TEST("HttpClient pipeline") {
auto io = kj::setupAsyncIo();
auto pipe = io.provider->newTwoWayPipe();
auto readRequestsPromise = pipe.ends[1]->readAllText();
auto allRequestText =
kj::strArray(KJ_MAP(testCase, PIPELINE_TESTS) { return testCase.request.raw; }, "");
auto allResponseText =
kj::strArray(KJ_MAP(testCase, PIPELINE_TESTS) { return testCase.response.raw; }, "");
auto writeResponsesPromise = pipe.ends[1]->write(allResponseText.begin(), allResponseText.size());
kj::Promise<void> writeResponsesPromise = kj::READY_NOW;
for (auto& testCase: PIPELINE_TESTS) {
writeResponsesPromise = writeResponsesPromise
.then([&]() {
return expectRead(*pipe.ends[1], testCase.request.raw);
}).then([&]() {
return pipe.ends[1]->write(testCase.response.raw.begin(), testCase.response.raw.size());
});
}
HttpHeaderTable table;
auto client = newHttpClient(table, *pipe.ends[0]);
......@@ -928,9 +929,6 @@ KJ_TEST("HttpClient pipeline") {
client = nullptr;
pipe.ends[0]->shutdownWrite();
auto requests = readRequestsPromise.wait(io.waitScope);
KJ_EXPECT(requests == allRequestText, requests);
writeResponsesPromise.wait(io.waitScope);
}
......@@ -938,14 +936,15 @@ KJ_TEST("HttpClient parallel pipeline") {
auto io = kj::setupAsyncIo();
auto pipe = io.provider->newTwoWayPipe();
auto readRequestsPromise = pipe.ends[1]->readAllText();
auto allRequestText =
kj::strArray(KJ_MAP(testCase, PIPELINE_TESTS) { return testCase.request.raw; }, "");
auto allResponseText =
kj::strArray(KJ_MAP(testCase, PIPELINE_TESTS) { return testCase.response.raw; }, "");
auto writeResponsesPromise = pipe.ends[1]->write(allResponseText.begin(), allResponseText.size());
kj::Promise<void> writeResponsesPromise = kj::READY_NOW;
for (auto& testCase: PIPELINE_TESTS) {
writeResponsesPromise = writeResponsesPromise
.then([&]() {
return expectRead(*pipe.ends[1], testCase.request.raw);
}).then([&]() {
return pipe.ends[1]->write(testCase.response.raw.begin(), testCase.response.raw.size());
});
}
HttpHeaderTable table;
auto client = newHttpClient(table, *pipe.ends[0]);
......@@ -983,9 +982,6 @@ KJ_TEST("HttpClient parallel pipeline") {
client = nullptr;
pipe.ends[0]->shutdownWrite();
auto requests = readRequestsPromise.wait(io.waitScope);
KJ_EXPECT(requests == allRequestText, requests);
writeResponsesPromise.wait(io.waitScope);
}
......
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