Skip to content

Commit

Permalink
Don't fail native test start when http is not exposed
Browse files Browse the repository at this point in the history
fixes quarkusio#21317

(cherry picked from commit 7e43de2)
  • Loading branch information
michalszynkiewicz authored and gsmet committed Nov 24, 2021
1 parent 1176ee1 commit fd04f9f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
6 changes: 6 additions & 0 deletions extensions/grpc/codegen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-protoc-plugin</artifactId>
<classifier>shaded</classifier>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

public final class LauncherUtil {

public static final int LOG_CHECK_INTERVAL = 500;

private LauncherUtil() {
}

Expand Down Expand Up @@ -106,7 +108,7 @@ private static void destroyProcess(Process quarkusProcess) {
int i = 0;
while (i++ < 10) {
try {
Thread.sleep(500);
Thread.sleep(LOG_CHECK_INTERVAL);
} catch (InterruptedException ignored) {

}
Expand Down Expand Up @@ -177,11 +179,13 @@ static IntegrationTestStartedNotifier.Result waitForStartedFunction(
* process is listening
*/
static void updateConfigForPort(Integer effectivePort) {
System.setProperty("quarkus.http.port", effectivePort.toString()); //set the port as a system property in order to have it applied to Config
System.setProperty("quarkus.http.test-port", effectivePort.toString()); // needed for RestAssuredManager
installAndGetSomeConfig(); // reinitialize the configuration to make sure the actual port is used
System.clearProperty("test.url"); // make sure the old value does not interfere with setting the new one
System.setProperty("test.url", TestHTTPResourceManager.getUri());
if (effectivePort != null) {
System.setProperty("quarkus.http.port", effectivePort.toString()); //set the port as a system property in order to have it applied to Config
System.setProperty("quarkus.http.test-port", effectivePort.toString()); // needed for RestAssuredManager
installAndGetSomeConfig(); // reinitialize the configuration to make sure the actual port is used
System.clearProperty("test.url"); // make sure the old value does not interfere with setting the new one
System.setProperty("test.url", TestHTTPResourceManager.getUri());
}
}

/**
Expand All @@ -195,6 +199,7 @@ private static class CaptureListeningDataReader implements Runnable {
private final CountDownLatch signal;
private final AtomicReference<ListeningAddress> resultReference;
private final Pattern listeningRegex = Pattern.compile("Listening on:\\s+(https?)://\\S*:(\\d+)");
private final Pattern startedRegex = Pattern.compile(".*Quarkus .* started in \\d+.*s.*");

public CaptureListeningDataReader(Path processOutput, Duration waitTime, CountDownLatch signal,
AtomicReference<ListeningAddress> resultReference) {
Expand All @@ -213,9 +218,19 @@ public void run() {

long bailoutTime = System.currentTimeMillis() + waitTime.toMillis();
try (BufferedReader reader = new BufferedReader(new FileReader(processOutput.toFile()))) {
long timeStarted = Long.MAX_VALUE;
boolean started = false;
// generally, we want to start as soon as info about Quarkus having started is printed
// but just in case the line with http host and port is printed later, let's wait a bit more
while (true) {
if (reader.ready()) { // avoid blocking as the input is a file which continually gets more data added
String line = reader.readLine();

if (startedRegex.matcher(line).matches()) {
timeStarted = System.currentTimeMillis();
started = true;
}

Matcher regexMatcher = listeningRegex.matcher(line);
if (regexMatcher.find()) {
dataDetermined(regexMatcher.group(1), Integer.valueOf(regexMatcher.group(2)));
Expand All @@ -228,17 +243,26 @@ public void run() {
}
} else {
//wait until there is more of the file for us to read

long now = System.currentTimeMillis();
// if we have seen info that the app is started in the log a while ago
// or waiting the the next check interval will exceed the bailout time, it's time to finish waiting:
if (now + LOG_CHECK_INTERVAL > bailoutTime || now - 2 * LOG_CHECK_INTERVAL > timeStarted) {
if (started) {
dataDetermined(null, null); // no http, all is null
} else {
unableToDetermineData("Waited " + waitTime.getSeconds() + " seconds for " + processOutput
+ " to contain info about the listening port and protocol but no such info was found");
}
return;
}

try {
Thread.sleep(500);
Thread.sleep(LOG_CHECK_INTERVAL);
} catch (InterruptedException e) {
unableToDetermineData(
"Thread interrupted while waiting for more data to become available in proccess output file: "
+ processOutput.toAbsolutePath().toString());
return;
}
if (System.currentTimeMillis() > bailoutTime) {
unableToDetermineData("Waited " + waitTime.getSeconds() + "seconds for " + processOutput
+ " to contain info about the listening port and protocol but no such info was found");
"Thread interrupted while waiting for more data to become available in process output file: "
+ processOutput.toAbsolutePath());
return;
}
}
Expand Down

0 comments on commit fd04f9f

Please sign in to comment.