Skip to content

Commit

Permalink
Merge pull request quarkusio#41641 from holly-cummins/check-port-is-free
Browse files Browse the repository at this point in the history
Check port is free before starting Quarkus in our dev mode tests
  • Loading branch information
geoand authored Jul 3, 2024
2 parents f65c775 + 0705b68 commit d15a83e
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.quarkus.maven.it;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -75,6 +77,8 @@ protected void run(boolean performCompile, LaunchMode mode, String... options)
protected void run(boolean performCompile, LaunchMode mode, boolean skipAnalytics, String... options)
throws FileNotFoundException, MavenInvocationException {
assertThat(testDir).isDirectory();
assertThatPortIsFree();

running = new RunningInvoker(testDir, false);

final List<String> args = new ArrayList<>(3 + options.length);
Expand Down Expand Up @@ -114,6 +118,17 @@ protected void run(boolean performCompile, LaunchMode mode, boolean skipAnalytic
running.execute(args, Map.of());
}

private void assertThatPortIsFree() {
try {
// Call get(), which doesn't retry - otherwise, tests will go very slow
devModeClient.get();
fail("The port " + getPort()
+ " appears to be in use before starting the test instance of Quarkus, so any tests will give unpredictable results.");
} catch (IOException e) {
// All good, we wanted this
}
}

protected void runAndCheck(String... options) throws FileNotFoundException, MavenInvocationException {
runAndCheck(true, options);
}
Expand Down

0 comments on commit d15a83e

Please sign in to comment.