Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nlisker committed Jan 30, 2024
1 parent 1328105 commit 8880aa7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -40,8 +40,6 @@ public void testAnimation() throws InterruptedException {
}

private void startAnimation() {
registerExceptionHandler();

var anim = new StrokeTransition(Duration.millis(10));
anim.setCycleCount(Animation.INDEFINITE);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -38,8 +38,6 @@ public void testAnimationTimer() throws InterruptedException {
}

private void startAnimationTimer() {
registerExceptionHandler();

var timer = new AnimationTimer() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ public static void shutdown() {
private final AtomicReference<Throwable> throwable = new AtomicReference<>();

protected void runTest(Runnable runnable) throws InterruptedException {
Platform.runLater(() -> registerExceptionHandler());
Platform.runLater(() -> Thread.currentThread().setUncaughtExceptionHandler(this::handleThrowable));

Runnable wrappedRunnable = wrap(runnable);

for (int i = 0; i < 10; i++) {
executor.submit(runnable);
executor.submit(wrappedRunnable);
}

// If no exception is thrown after GRACE_PERIOD seconds, await completes and the test will succeed.
Expand All @@ -94,12 +96,20 @@ protected void runTest(Runnable runnable) throws InterruptedException {
assertFalse(failed.get(), "<" + throwable.get() + "> was thrown on " + thread.get());
}

protected void registerExceptionHandler() {
Thread.currentThread().setUncaughtExceptionHandler((t, e) -> {
thread.set(t);
throwable.set(e);
failed.set(true);
waiter.countDown();
});
private Runnable wrap(Runnable runnable) {
return () -> {
try {
runnable.run();
} catch (Throwable e) {
handleThrowable(Thread.currentThread(), e);
}
};
}

private void handleThrowable(Thread t, Throwable e) {
thread.set(t);
throwable.set(e);
failed.set(true);
waiter.countDown();
}
}

0 comments on commit 8880aa7

Please sign in to comment.