Skip to content

Commit

Permalink
[CPP tests] Wait for mockZTS to start before connecting to it (apache…
Browse files Browse the repository at this point in the history
…#15924)

* [CPP tests] Wait for mockZTS to start before connecting to it

* Apply suggestions from code review: use reference instead of pointer

Co-authored-by: Matteo Merli <[email protected]>

Co-authored-by: Matteo Merli <[email protected]>
  • Loading branch information
lhotari and merlimat authored Jun 3, 2022
1 parent 011ebce commit 93c1a4c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pulsar-client-cpp/tests/AuthPluginTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <lib/LogUtils.h>
#include <lib/auth/AuthOauth2.h>

#include <lib/Latch.h>
#include "lib/Future.h"
#include "lib/Utils.h"
DECLARE_LOG_OBJECT()
Expand Down Expand Up @@ -190,14 +191,15 @@ TEST(AuthPluginTest, testTlsDetectHttpsWithHostNameValidation) {

namespace testAthenz {
std::string principalToken;
void mockZTS(int port) {
void mockZTS(Latch& latch, int port) {
LOG_INFO("-- MockZTS started");
boost::asio::io_service io;
boost::asio::ip::tcp::iostream stream;
boost::asio::ip::tcp::acceptor acceptor(io,
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port));

LOG_INFO("-- MockZTS waiting for connnection");
latch.countdown();
acceptor.accept(*stream.rdbuf());
LOG_INFO("-- MockZTS got connection");

Expand Down Expand Up @@ -226,7 +228,8 @@ void mockZTS(int port) {
} // namespace testAthenz

TEST(AuthPluginTest, testAthenz) {
std::thread zts(std::bind(&testAthenz::mockZTS, 9999));
Latch latch(1);
std::thread zts(std::bind(&testAthenz::mockZTS, std::ref(latch), 9999));
pulsar::AuthenticationDataPtr data;
std::string params = R"({
"tenantDomain": "pulsar.test.tenant",
Expand All @@ -238,6 +241,7 @@ TEST(AuthPluginTest, testAthenz) {
})";

LOG_INFO("PARAMS: " << params);
latch.wait();
pulsar::AuthenticationPtr auth = pulsar::AuthAthenz::create(params);
ASSERT_EQ(auth->getAuthMethodName(), "athenz");
ASSERT_EQ(auth->getAuthData(data), pulsar::ResultOk);
Expand Down Expand Up @@ -296,7 +300,8 @@ TEST(AuthPluginTest, testAuthFactoryTls) {
}

TEST(AuthPluginTest, testAuthFactoryAthenz) {
std::thread zts(std::bind(&testAthenz::mockZTS, 9998));
Latch latch(1);
std::thread zts(std::bind(&testAthenz::mockZTS, std::ref(latch), 9998));
pulsar::AuthenticationDataPtr data;
std::string params = R"({
"tenantDomain": "pulsar.test2.tenant",
Expand All @@ -307,6 +312,7 @@ TEST(AuthPluginTest, testAuthFactoryAthenz) {
"ztsUrl": "http://localhost:9998"
})";
LOG_INFO("PARAMS: " << params);
latch.wait();
pulsar::AuthenticationPtr auth = pulsar::AuthFactory::create("athenz", params);
ASSERT_EQ(auth->getAuthMethodName(), "athenz");
ASSERT_EQ(auth->getAuthData(data), pulsar::ResultOk);
Expand Down

0 comments on commit 93c1a4c

Please sign in to comment.