Skip to content

Commit c595f96

Browse files
author
Alexey Semenyuk
committed
8299278: tools/jpackage/share/AddLauncherTest.java#id1 failed AddLauncherTest.bug8230933
Reviewed-by: almatvee
1 parent 3c99e78 commit c595f96

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Executor.java

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.List;
3838
import java.util.Objects;
3939
import java.util.Set;
40+
import java.util.function.Supplier;
4041
import java.util.regex.Pattern;
4142
import java.util.spi.ToolProvider;
4243
import java.util.stream.Collectors;
@@ -235,18 +236,49 @@ public List<String> executeAndGetOutput() {
235236
return saveOutput().execute().getOutput();
236237
}
237238

239+
private static class BadResultException extends RuntimeException {
240+
BadResultException(Result v) {
241+
value = v;
242+
}
243+
244+
Result getValue() {
245+
return value;
246+
}
247+
248+
private final Result value;
249+
}
250+
238251
/*
239252
* Repeates command "max" times and waits for "wait" seconds between each
240253
* execution until command returns expected error code.
241254
*/
242255
public Result executeAndRepeatUntilExitCode(int expectedCode, int max, int wait) {
243-
Result result;
256+
try {
257+
return tryRunMultipleTimes(() -> {
258+
Result result = executeWithoutExitCodeCheck();
259+
if (result.getExitCode() != expectedCode) {
260+
throw new BadResultException(result);
261+
}
262+
return result;
263+
}, max, wait).assertExitCodeIs(expectedCode);
264+
} catch (BadResultException ex) {
265+
return ex.getValue().assertExitCodeIs(expectedCode);
266+
}
267+
}
268+
269+
/*
270+
* Repeates a "task" "max" times and waits for "wait" seconds between each
271+
* execution until the "task" returns without throwing an exception.
272+
*/
273+
public static <T> T tryRunMultipleTimes(Supplier<T> task, int max, int wait) {
274+
RuntimeException lastException = null;
244275
int count = 0;
245276

246277
do {
247-
result = executeWithoutExitCodeCheck();
248-
if (result.getExitCode() == expectedCode) {
249-
return result;
278+
try {
279+
return task.get();
280+
} catch (RuntimeException ex) {
281+
lastException = ex;
250282
}
251283

252284
try {
@@ -258,7 +290,14 @@ public Result executeAndRepeatUntilExitCode(int expectedCode, int max, int wait)
258290
count++;
259291
} while (count < max);
260292

261-
return result.assertExitCodeIs(expectedCode);
293+
throw lastException;
294+
}
295+
296+
public static void tryRunMultipleTimes(Runnable task, int max, int wait) {
297+
tryRunMultipleTimes(() -> {
298+
task.run();
299+
return null;
300+
}, max, wait);
262301
}
263302

264303
public List<String> executeWithoutExitCodeCheckAndGetOutput() {

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LauncherIconVerifier.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ void verifyLauncherIcon(JPackageCommand cmd, String launcherName,
9494
Files.copy(getDefaultAppLauncher(expectedIcon == null
9595
&& !expectedDefault), iconContainer);
9696
if (expectedIcon != null) {
97-
setIcon(expectedIcon, iconContainer);
97+
Executor.tryRunMultipleTimes(() -> {
98+
setIcon(expectedIcon, iconContainer);
99+
}, 3, 5);
98100
}
99101

100102
Path extractedExpectedIcon = extractIconFromExecutable(

0 commit comments

Comments
 (0)