File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/util Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -58,21 +58,23 @@ public void testStartProvideAwaitNormal() throws Throwable {
5858 */
5959 @ Test (timeout = 1000 )
6060 public void testAwaitDoesNotHangWhenContextCallableFails () throws Throwable {
61- ExecutorService executor = Executors .newSingleThreadExecutor ( );
61+ ExecutorService executor = Executors .newFixedThreadPool ( 1 );
6262 try {
63+ // Use AssertionError to bypass the inner catch(Exception) loop in runAndDone()
64+ // This simulates a scenario where an exception escapes the task logic
65+ // (similar to how a ContextCallable failure would behave from safeRun's perspective)
6366 Consumers <Integer > consumers = new Consumers <>(executor , v -> {
64- // Never reached
67+ throw new AssertionError ( "Simulated fatal error (OOM/StackOverflow/etc)" );
6568 });
66-
67- /*
68- * start() creates ContextCallable internally.
69- * If ContextCallable.call() fails before runAndDone(),
70- * safeRun().finally MUST count down the latch.
71- */
72- consumers .start ("test" );
73-
74- // If the fix is missing, this call hangs forever.
69+ consumers .start ("test-fatal-error" );
70+ consumers .provide (1 );
71+ // Verification:
72+ // Without the fix, the latch would never be decremented (because runAndDone crashes), causing await() to hang.
73+ // With the fix (safeRun wrapper), the finally block ensures latch.countDown() is called.
7574 consumers .await ();
75+
76+ // Note: consumer.exception will be null because safeRun only catches Exception, not Error.
77+ // This is acceptable behavior for fatal errors, as long as it doesn't deadlock.
7678 } finally {
7779 executor .shutdownNow ();
7880 }
You can’t perform that action at this time.
0 commit comments