Skip to content

Commit 6b5dfa6

Browse files
More tests for Promise listeners that throw errors
1 parent 0b609a4 commit 6b5dfa6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

test/com/linkedin/parseq/promise/TestSettablePromise.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ public void onResolved(Promise<String> promise)
344344
assertEquals("Done!", promise.get());
345345
}
346346

347-
348347
@Test
349348
public void testListenerThrowsError() throws InterruptedException
350349
{
@@ -364,4 +363,24 @@ public void onResolved(Promise<String> promise)
364363
assertTrue(promise.await(5, TimeUnit.SECONDS));
365364
assertEquals("Done!", promise.get());
366365
}
366+
367+
@Test
368+
public void testListenerThrowsErrorAfterPromiseDone() throws InterruptedException
369+
{
370+
// This test ensures that we catch and do not rethrow errors from listeners
371+
// even if they are added after the promise is done.
372+
final SettablePromise<String> promise = Promises.settable();
373+
promise.done("Done!");
374+
assertTrue(promise.await(5, TimeUnit.SECONDS));
375+
376+
// This should not throw
377+
promise.addListener(new PromiseListener<String>()
378+
{
379+
@Override
380+
public void onResolved(Promise<String> promise)
381+
{
382+
throw new Error();
383+
}
384+
});
385+
}
367386
}

0 commit comments

Comments
 (0)