cobra metrics publisher test uses random free port

This commit is contained in:
Benjamin Sergeant 2019-09-05 22:03:47 -07:00
parent e81c2c3e5c
commit 2ce65e7a77

View File

@ -20,7 +20,6 @@ namespace
// This project / appkey is configure on cobra to not do any batching. // This project / appkey is configure on cobra to not do any batching.
// This way we can start a subscriber and receive all messages as they come in. // This way we can start a subscriber and receive all messages as they come in.
// //
std::string ENDPOINT("ws://localhost:8009");
std::string APPKEY("FC2F10139A2BAc53BB72D9db967b024f"); std::string APPKEY("FC2F10139A2BAc53BB72D9db967b024f");
std::string CHANNEL("unittest_channel"); std::string CHANNEL("unittest_channel");
std::string PUBLISHER_ROLE("_pub"); std::string PUBLISHER_ROLE("_pub");
@ -39,14 +38,14 @@ namespace
// //
// Background thread subscribe to the channel and validates what was sent // Background thread subscribe to the channel and validates what was sent
// //
void startSubscriber() void startSubscriber(const std::string& endpoint)
{ {
gSubscriberConnectedAndSubscribed = false; gSubscriberConnectedAndSubscribed = false;
gUniqueMessageIdsCount = 0; gUniqueMessageIdsCount = 0;
gMessageCount = 0; gMessageCount = 0;
ix::CobraConnection conn; ix::CobraConnection conn;
conn.configure(APPKEY, ENDPOINT, SUBSCRIBER_ROLE, SUBSCRIBER_SECRET, conn.configure(APPKEY, endpoint, SUBSCRIBER_ROLE, SUBSCRIBER_SECRET,
ix::WebSocketPerMessageDeflateOptions(true)); ix::WebSocketPerMessageDeflateOptions(true));
conn.connect(); conn.connect();
@ -122,15 +121,20 @@ namespace
TEST_CASE("Cobra_Metrics_Publisher", "[cobra]") TEST_CASE("Cobra_Metrics_Publisher", "[cobra]")
{ {
snake::AppConfig appConfig = makeSnakeServerConfig(8009); int port = getFreePort();
snake::AppConfig appConfig = makeSnakeServerConfig(port);
snake::SnakeServer snakeServer(appConfig); snake::SnakeServer snakeServer(appConfig);
snakeServer.run(); snakeServer.run();
std::stringstream ss;
ss << "ws://localhost:" << port;
std::string endpoint = ss.str();
// Make channel name unique // Make channel name unique
CHANNEL += uuid4(); CHANNEL += uuid4();
gStop = false; gStop = false;
std::thread bgThread(&startSubscriber); std::thread bgThread(&startSubscriber, endpoint);
int timeout = 10 * 1000; // 10s int timeout = 10 * 1000; // 10s
@ -150,7 +154,7 @@ TEST_CASE("Cobra_Metrics_Publisher", "[cobra]")
ix::CobraMetricsPublisher cobraMetricsPublisher; ix::CobraMetricsPublisher cobraMetricsPublisher;
bool perMessageDeflate = true; bool perMessageDeflate = true;
cobraMetricsPublisher.configure(APPKEY, ENDPOINT, CHANNEL, cobraMetricsPublisher.configure(APPKEY, endpoint, CHANNEL,
PUBLISHER_ROLE, PUBLISHER_SECRET, perMessageDeflate); PUBLISHER_ROLE, PUBLISHER_SECRET, perMessageDeflate);
cobraMetricsPublisher.setSession(uuid4()); cobraMetricsPublisher.setSession(uuid4());
cobraMetricsPublisher.enable(true); // disabled by default, needs to be enabled to be active cobraMetricsPublisher.enable(true); // disabled by default, needs to be enabled to be active