Commit ac856c32 authored by Dennis Jenkins's avatar Dennis Jenkins

Use emphemeral port for unit test.

parent 2be5c97d
...@@ -38,6 +38,10 @@ public: ...@@ -38,6 +38,10 @@ public:
httpEndpoint->shutdown(); httpEndpoint->shutdown();
} }
Port getPort() const {
return httpEndpoint->getPort();
}
private: private:
void setupRoutes() { void setupRoutes() {
using namespace Rest; using namespace Rest;
...@@ -56,20 +60,21 @@ private: ...@@ -56,20 +60,21 @@ private:
}; };
TEST(rest_server_test, basic_test) { TEST(rest_server_test, basic_test) {
Port port(9090);
int thr = 1; int thr = 1;
Address addr(Ipv4::any(), port); Address addr(Ipv4::any(), Port(0));
StatsEndpoint stats(addr); StatsEndpoint stats(addr);
stats.init(thr); stats.init(thr);
stats.start(); stats.start();
Port port = stats.getPort();
cout << "Cores = " << hardware_concurrency() << endl; cout << "Cores = " << hardware_concurrency() << endl;
cout << "Using " << thr << " threads" << endl; cout << "Using " << thr << " threads" << endl;
cout << "Port = " << port << endl;
httplib::Client client("localhost", 9090); httplib::Client client("localhost", port);
auto res = client.Get("/read/function1"); auto res = client.Get("/read/function1");
ASSERT_EQ(res->status, 200); ASSERT_EQ(res->status, 200);
ASSERT_EQ(res->body, "1"); ASSERT_EQ(res->body, "1");
......
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