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

Fixing payload_test

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