Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow testing of an existing executable #5609

Merged
merged 1 commit into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/src/main/asciidoc/building-native-image.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@ that does not call your HTTP endpoints, it's probably not a good idea to run the
If you share your test class between JVM and native executions like we advise above, you can mark certain tests
with the `@DisabledOnNativeImage` annotation in order to only run them on the JVM.


=== Testing an existing native executable

It is also possible to re-run the tests against a native executable that has already been built. To do this run
`./mvnw failsafe:integration-test`. This will discover the existing native image and run the tests against it using
failsafe.

If the process cannot find the native image for some reason, or you want to test a native image that is no longer in the
target directory you can specify the executable with the `-Dnative.image.path=` system property.

== Creating a container

IMPORTANT: Before going further, be sure to have a working container runtime (Docker, podman) environment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,24 @@ private static String guessPath(Class<?> testClass) {
return file.getAbsolutePath();
}
}
} else if (url.getProtocol().equals("file") && url.getPath().contains("/target/surefire/")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will these paths work on Windows?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, it is a URL path so I think so, either way windows support for native is pretty limited at the moment AFAIK, and the runner would probably have a .exe extension so that would not work either.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

//this will make mvn failsafe:integration-test work
String path = url.getPath();
int index = path.lastIndexOf("/target/");
File targetDir = new File(path.substring(0, index) + "/target/");
for (File file : targetDir.listFiles()) {
if (file.getName().endsWith("-runner")) {
logGuessedPath(file.getAbsolutePath());
return file.getAbsolutePath();
}
}

}
}
}

throw new RuntimeException("Unable to find native image, make sure native.image.path is set");
throw new RuntimeException(
"Unable to automatically find native image, please set the native.image.path to the native executable you wish to test");
}

private static void logGuessedPath(String guessedPath) {
Expand All @@ -133,6 +146,9 @@ private void waitForQuarkus() {
long bailout = System.currentTimeMillis() + imageWaitTime * 1000;

while (System.currentTimeMillis() < bailout) {
if (!quarkusProcess.isAlive()) {
throw new RuntimeException("Failed to start native image, process has exited");
}
try {
Thread.sleep(100);
for (NativeImageStartedNotifier i : startedNotifiers) {
Expand Down