Commit 65c3ce4a authored by Ian Roddis's avatar Ian Roddis

Fixing payload_test

parent a66ad1e5
......@@ -30,29 +30,32 @@ typedef std::vector<TestSet> PayloadTestSets;
void testPayloads(std::string url, PayloadTestSets & testPayloads) {
// Client tests to make sure the payload is enforced
std::vector<Async::Promise<Http::Response> > responses;
std::mutex resultsetMutex;
PayloadTestSets test_results;
for (size_t times = 0; times < 10; ++times) {
Http::Client client;
auto client_opts = Http::Client::options().threads(1).maxConnectionsPerHost(1);
client.init(client_opts);
for (auto & t : testPayloads) {
auto rb = client.post(url);
std::string payload(t.bytes, 'A');
auto response = rb.body(payload).send();
response.then([t,&test_results](Http::Response rsp) {
TestSet res(t);
res.actualCode = rsp.code();
Http::Client client;
auto client_opts = Http::Client::options()
.threads(1)
.maxConnectionsPerHost(1);
client.init(client_opts);
auto rb = client.post(url);
for (auto & t : testPayloads) {
std::string payload(t.bytes, 'A');
std::vector<Async::Promise<Http::Response> > responses;
auto response = rb.body(payload).send();
response.then([t,&test_results,&resultsetMutex](Http::Response rsp) {
TestSet res(t);
res.actualCode = rsp.code();
{
std::unique_lock<std::mutex> lock(resultsetMutex);
test_results.push_back(res);
}, Async::IgnoreException);
responses.push_back(std::move(response));
}
}
}, Async::IgnoreException);
responses.push_back(std::move(response));
auto sync = Async::whenAll(responses.begin(), responses.end());
Async::Barrier<std::vector<Http::Response>> barrier(sync);
barrier.wait_for(std::chrono::seconds(5));
client.shutdown();
}
client.shutdown();
for (auto & result : test_results) {
ASSERT_EQ(result.expectedCode, result.actualCode);
......@@ -66,7 +69,7 @@ void handleEcho(const Rest::Request&req, Http::ResponseWriter response) {
TEST(payload_test, from_description)
{
Address addr(Ipv4::any(), 9084);
const size_t threads = 2;
const size_t threads = 20;
const size_t maxPayload = 1024; // very small
std::shared_ptr<Http::Endpoint> endpoint;
......@@ -128,7 +131,7 @@ TEST(payload_test, manual_construction) {
};
Port port(9080);
int thr = 2;
int thr = 20;
Address addr(Ipv4::any(), port);
auto endpoint = std::make_shared<Http::Endpoint>(addr);
size_t maxPayload = 2048;
......
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