Skip to content

Commit 078e323

Browse files
committed
8299278: tools/jpackage/share/AddLauncherTest.java#id1 failed AddLauncherTest.bug8230933
Backport-of: c595f965abcf0ea80ace87b8f2180feebbb8984e
1 parent ea2dd16 commit 078e323

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;
@@ -250,18 +251,49 @@ public List<String> executeAndGetOutput() {
250251
return saveOutput().execute().getOutput();
251252
}
252253

254+
private static class BadResultException extends RuntimeException {
255+
BadResultException(Result v) {
256+
value = v;
257+
}
258+
259+
Result getValue() {
260+
return value;
261+
}
262+
263+
private final Result value;
264+
}
265+
253266
/*
254267
* Repeates command "max" times and waits for "wait" seconds between each
255268
* execution until command returns expected error code.
256269
*/
257270
public Result executeAndRepeatUntilExitCode(int expectedCode, int max, int wait) {
258-
Result result;
271+
try {
272+
return tryRunMultipleTimes(() -> {
273+
Result result = executeWithoutExitCodeCheck();
274+
if (result.getExitCode() != expectedCode) {
275+
throw new BadResultException(result);
276+
}
277+
return result;
278+
}, max, wait).assertExitCodeIs(expectedCode);
279+
} catch (BadResultException ex) {
280+
return ex.getValue().assertExitCodeIs(expectedCode);
281+
}
282+
}
283+
284+
/*
285+
* Repeates a "task" "max" times and waits for "wait" seconds between each
286+
* execution until the "task" returns without throwing an exception.
287+
*/
288+
public static <T> T tryRunMultipleTimes(Supplier<T> task, int max, int wait) {
289+
RuntimeException lastException = null;
259290
int count = 0;
260291

261292
do {
262-
result = executeWithoutExitCodeCheck();
263-
if (result.getExitCode() == expectedCode) {
264-
return result;
293+
try {
294+
return task.get();
295+
} catch (RuntimeException ex) {
296+
lastException = ex;
265297
}
266298

267299
try {
@@ -273,7 +305,14 @@ public Result executeAndRepeatUntilExitCode(int expectedCode, int max, int wait)
273305
count++;
274306
} while (count < max);
275307

276-
return result.assertExitCodeIs(expectedCode);
308+
throw lastException;
309+
}
310+
311+
public static void tryRunMultipleTimes(Runnable task, int max, int wait) {
312+
tryRunMultipleTimes(() -> {
313+
task.run();
314+
return null;
315+
}, max, wait);
277316
}
278317

279318
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)