Skip to content

Commit

Permalink
Check that the server is actually ready to serve http
Browse files Browse the repository at this point in the history
  • Loading branch information
Smjert committed Oct 19, 2024
1 parent 907fd18 commit b0e569a
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions osquery/remote/tests/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* SPDX-License-Identifier: (Apache-2.0 OR GPL-2.0-only)
*/

#include "osquery/remote/transports/tls.h"
#include <csignal>
#include <ctime>

Expand All @@ -18,15 +19,15 @@
#include <osquery/database/database.h>
#include <osquery/logger/logger.h>
#include <osquery/process/process.h>
#include <osquery/remote/requests.h>
#include <osquery/remote/serializers/json.h>
#include <osquery/remote/tests/test_utils.h>
#include <osquery/sql/sql.h>
#include <osquery/tests/test_util.h>
#include <osquery/utils/conversions/join.h>
#include <osquery/utils/json/json.h>
#include <osquery/utils/system/time.h>

namespace fs = boost::filesystem;

namespace osquery {

DECLARE_string(tls_hostname);
Expand Down Expand Up @@ -156,7 +157,25 @@ bool TLSServerRunner::start(const std::string& server_cert,
return false;
}

LOG(WARNING) << "Python server started correctly";
LOG(WARNING) << "Python server process started correctly";

// Verify that the server is also actually ready to serve
retry = 0;
setClientConfig();
while (retry < max_retry) {
std::string ping_server_uri =
"https://localhost:" + std::string(self.port_);

Request<TLSTransport, JSONSerializer> request(ping_server_uri);
Status status = request.call();
if (!status.ok()) {
LOG(WARNING) << "Python HTTP Server not ready yet: "
<< status.getMessage();
sleepFor(1000);
++retry;
}
}
unsetClientConfig();

return true;
}
Expand Down

0 comments on commit b0e569a

Please sign in to comment.