martinzink commented on code in PR #1457:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1457#discussion_r1085092236


##########
extensions/standard-processors/tests/unit/PutTCPTests.cpp:
##########
@@ -238,27 +220,22 @@ class PutTCPTestFixture {
   const std::shared_ptr<PutTCP> put_tcp_ = std::make_shared<PutTCP>("PutTCP");
   test::SingleProcessorTestController controller_{put_tcp_};
 
-  std::mt19937 random_engine_{std::random_device{}()};  // NOLINT: "Missing 
space before {  [whitespace/braces] [5]"
-  // most systems use ports 32768 - 65535 as ephemeral ports, so avoid binding 
to those
-
   class Server {
    public:
     Server() = default;
 
-    void startTCPServer(uint16_t port) {
-      gsl_Expects(!listener_ && !server_thread_.joinable());
-      listener_ = std::make_unique<SessionAwareTcpServer>(std::nullopt, port, 
core::logging::LoggerFactory<utils::net::Server>::getLogger());
-      server_thread_ = std::thread([this]() { listener_->run(); });
-    }
-
-    void startSSLServer(uint16_t port) {
+    uint16_t startTCPServer(std::optional<utils::net::SslServerOptions> 
ssl_server_options) {
       gsl_Expects(!listener_ && !server_thread_.joinable());
-      listener_ = std::make_unique<SessionAwareSslServer>(std::nullopt,
-                                                          port,
-                                                          
core::logging::LoggerFactory<utils::net::Server>::getLogger(),
-                                                          
createSslDataForServer(),
-                                                          
utils::net::SslServer::ClientAuthOption::REQUIRED);
+      listener_ = std::make_unique<CancellableTcpServer>(std::nullopt, 0, 
core::logging::LoggerFactory<utils::net::Server>::getLogger(), 
std::move(ssl_server_options));
       server_thread_ = std::thread([this]() { listener_->run(); });
+      uint16_t port = listener_->getPort();
+      auto deadline = std::chrono::steady_clock::now() + 200ms;
+      while (port == 0 && deadline > std::chrono::steady_clock::now()) {
+        std::this_thread::sleep_for(20ms);
+        port = listener_->getPort();
+      }
+      REQUIRE(port != 0);
+      return port;

Review Comment:
   good idea, I've included this (with a smaller check interval) in 
https://github.com/apache/nifi-minifi-cpp/pull/1457/commits/f37cffb3fe783683d38646b198dfc38f7a439ce4#diff-bbb56b112b398a6450c23e71e5dbbfb17bf20dad3d2fb908a1c6de26118f9ee8R232-R233



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to