Skip to content

Commit add9f8f

Browse files
authored
Adding debug mode (#296)
1 parent 9e26a98 commit add9f8f

File tree

7 files changed

+76
-64
lines changed

7 files changed

+76
-64
lines changed

temporal-sdk/src/main/java/io/temporal/internal/sync/DeterministicRunner.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@
3232
*/
3333
interface DeterministicRunner {
3434

35+
boolean debugMode = Boolean.parseBoolean(System.getenv("TEMPORAL_DEBUG_MODE"));
36+
3537
long DEFAULT_DEADLOCK_DETECTION_TIMEOUT = 1000;
3638

39+
static long getDeadlockDetectionTimeout() {
40+
return debugMode ? Long.MAX_VALUE : DEFAULT_DEADLOCK_DETECTION_TIMEOUT;
41+
}
42+
3743
static DeterministicRunner newRunner(Runnable root) {
3844
return new DeterministicRunnerImpl(root);
3945
}

temporal-sdk/src/main/java/io/temporal/internal/sync/SyncWorkflow.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
package io.temporal.internal.sync;
2121

22-
import static io.temporal.internal.sync.DeterministicRunner.DEFAULT_DEADLOCK_DETECTION_TIMEOUT;
22+
import static io.temporal.internal.sync.DeterministicRunner.getDeadlockDetectionTimeout;
2323

2424
import io.temporal.api.common.v1.Payloads;
2525
import io.temporal.api.common.v1.WorkflowType;
@@ -141,7 +141,7 @@ public boolean eventLoop() {
141141
if (runner == null) {
142142
return false;
143143
}
144-
runner.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
144+
runner.runUntilAllBlocked(getDeadlockDetectionTimeout());
145145
return runner.isDone() || workflowProc.isDone(); // Do not wait for all other threads.
146146
}
147147

temporal-sdk/src/main/java/io/temporal/internal/sync/WorkflowThreadContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
package io.temporal.internal.sync;
2121

22-
import static io.temporal.internal.sync.DeterministicRunner.DEFAULT_DEADLOCK_DETECTION_TIMEOUT;
22+
import static io.temporal.internal.sync.DeterministicRunner.getDeadlockDetectionTimeout;
2323

2424
import com.google.common.base.Throwables;
2525
import io.temporal.workflow.Functions;
@@ -271,7 +271,7 @@ public void destroy() {
271271
(r) -> {
272272
throw new DestroyWorkflowThreadError();
273273
});
274-
runUntilBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
274+
runUntilBlocked(getDeadlockDetectionTimeout());
275275
}
276276

277277
/** To be called only from a workflow thread. */

temporal-sdk/src/test/java/io/temporal/internal/sync/DeterministicRunnerTest.java

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
package io.temporal.internal.sync;
2121

22-
import static io.temporal.internal.sync.DeterministicRunner.DEFAULT_DEADLOCK_DETECTION_TIMEOUT;
22+
import static io.temporal.internal.sync.DeterministicRunner.getDeadlockDetectionTimeout;
2323
import static junit.framework.TestCase.*;
2424
import static org.junit.Assert.assertFalse;
2525
import static org.mockito.Mockito.*;
@@ -108,17 +108,17 @@ public void testYield() throws Throwable {
108108
status = "done";
109109
});
110110
assertEquals("initial", status);
111-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
111+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
112112
assertEquals("started", status);
113113
assertFalse(d.isDone());
114114
unblock1 = true;
115-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
115+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
116116
assertEquals("after1", status);
117117
// Just check that running again doesn't make any progress.
118-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
118+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
119119
assertEquals("after1", status);
120120
unblock2 = true;
121-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
121+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
122122
assertEquals("done", status);
123123
assertTrue(d.isDone());
124124
}
@@ -158,7 +158,7 @@ public void testRetry() throws Throwable {
158158
});
159159
try {
160160
for (int i = 0; i < Duration.ofSeconds(400).toMillis(); i += 10) {
161-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
161+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
162162
}
163163
fail("failure expected");
164164
} catch (IllegalThreadStateException e) {
@@ -189,12 +189,12 @@ public void testRootFailure() throws Throwable {
189189
throw new RuntimeException("simulated");
190190
});
191191
assertEquals("initial", status);
192-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
192+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
193193
assertEquals("started", status);
194194
assertFalse(d.isDone());
195195
unblock1 = true;
196196
try {
197-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
197+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
198198
fail("exception expected");
199199
} catch (Exception ignored) {
200200
}
@@ -218,11 +218,11 @@ public void testDispatcherStop() throws Throwable {
218218
status = "done";
219219
});
220220
assertEquals("initial", status);
221-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
221+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
222222
assertEquals("started", status);
223223
assertFalse(d.isDone());
224224
unblock1 = true;
225-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
225+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
226226
assertEquals("after1", status);
227227
d.close();
228228
assertTrue(d.isDone());
@@ -255,10 +255,10 @@ public void testDispatcherExit() throws Throwable {
255255
thread2.get();
256256
trace.add("root done");
257257
});
258-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
258+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
259259
assertFalse(d.isDone());
260260
unblock2 = true;
261-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
261+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
262262
assertTrue(d.isDone());
263263
assertEquals("exitValue", d.getExitValue());
264264
String[] expected =
@@ -282,10 +282,10 @@ public void testRootCancellation() throws Throwable {
282282
"reason1", () -> CancellationScope.current().isCancelRequested());
283283
trace.add("root done");
284284
});
285-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
285+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
286286
assertFalse(d.isDone());
287287
d.cancel("I just feel like it");
288-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
288+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
289289
assertTrue(d.isDone());
290290
String[] expected =
291291
new String[] {
@@ -320,7 +320,7 @@ public void testExplicitScopeCancellation() throws Throwable {
320320
}
321321
trace.add("root done");
322322
});
323-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
323+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
324324
assertTrue(trace.toString(), d.isDone());
325325
String[] expected =
326326
new String[] {
@@ -362,7 +362,7 @@ public void testExplicitDetachedScopeCancellation() throws Throwable {
362362
}
363363
trace.add("root done");
364364
});
365-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
365+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
366366
assertTrue(trace.toString(), d.isDone());
367367
String[] expected =
368368
new String[] {
@@ -420,7 +420,7 @@ public void testExplicitThreadCancellation() throws Throwable {
420420
trace.add("root done");
421421
});
422422

423-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
423+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
424424
assertTrue(d.stackTrace(), d.isDone());
425425
String[] expected =
426426
new String[] {
@@ -476,7 +476,7 @@ public void testExplicitCancellationOnFailure() throws Throwable {
476476
trace.add("root done");
477477
});
478478

479-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
479+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
480480
assertTrue(d.stackTrace(), d.isDone());
481481
String[] expected =
482482
new String[] {
@@ -525,10 +525,10 @@ public void testDetachedCancellation() throws Throwable {
525525
}
526526
trace.add("root done");
527527
});
528-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
528+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
529529
assertFalse(trace.toString(), d.isDone());
530530
d.cancel("I just feel like it");
531-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
531+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
532532
assertFalse(d.isDone());
533533
String[] expected =
534534
new String[] {
@@ -537,7 +537,7 @@ public void testDetachedCancellation() throws Throwable {
537537
trace.setExpected(expected);
538538
trace.assertExpected();
539539
unblock1 = true;
540-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
540+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
541541
assertTrue(d.stackTrace(), d.isDone());
542542
expected =
543543
new String[] {
@@ -563,17 +563,17 @@ public void testChild() throws Throwable {
563563
async.get();
564564
});
565565
assertEquals("initial", status);
566-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
566+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
567567
assertEquals("started", status);
568568
assertFalse(d.isDone());
569569
unblock1 = true;
570-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
570+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
571571
assertEquals("after1", status);
572572
// Just check that running again doesn't make any progress.
573-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
573+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
574574
assertEquals("after1", status);
575575
unblock2 = true;
576-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
576+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
577577
assertEquals("done", status);
578578
assertTrue(d.isDone());
579579
}
@@ -605,9 +605,9 @@ public void apply() {
605605
@Test
606606
public void testChildTree() throws Throwable {
607607
DeterministicRunner d = new DeterministicRunnerImpl(new TestChildTreeRunnable(0)::apply);
608-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
608+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
609609
unblock1 = true;
610-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
610+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
611611
assertTrue(d.isDone());
612612
List<String> expected = new ArrayList<>();
613613
for (int i = 0; i <= CHILDREN; i++) {
@@ -668,7 +668,7 @@ public void workflowThreadsWillEvictCacheWhenMaxThreadCountIsHit() throws Throwa
668668

669669
cache.getOrCreate(response, new com.uber.m3.tally.NoopScope(), () -> workflowRunTaskHandler);
670670
cache.addToCache(response.getWorkflowExecution().getRunId(), workflowRunTaskHandler);
671-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
671+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
672672
assertEquals(2, threadPool.getActiveCount());
673673
assertEquals(1, cache.size());
674674

@@ -689,7 +689,7 @@ public void workflowThreadsWillEvictCacheWhenMaxThreadCountIsHit() throws Throwa
689689
},
690690
cache);
691691
// Act: This should kick out threads consumed by 'd'
692-
d2.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
692+
d2.runUntilAllBlocked(getDeadlockDetectionTimeout());
693693

694694
// Assert: Cache is evicted and only threads consumed by d2 remain.
695695
assertEquals(2, threadPool.getActiveCount());
@@ -730,7 +730,7 @@ public void workflowThreadsWillNotEvictCacheWhenMaxThreadCountIsHit() throws Thr
730730

731731
cache.getOrCreate(response, new com.uber.m3.tally.NoopScope(), () -> workflowRunTaskHandler);
732732
cache.addToCache(response.getWorkflowExecution().getRunId(), workflowRunTaskHandler);
733-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
733+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
734734
assertEquals(2, threadPool.getActiveCount());
735735
assertEquals(1, cache.size());
736736

@@ -751,7 +751,7 @@ public void workflowThreadsWillNotEvictCacheWhenMaxThreadCountIsHit() throws Thr
751751
cache);
752752

753753
// Act: This should not kick out threads consumed by 'd' since there's enough capacity
754-
d2.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
754+
d2.runUntilAllBlocked(getDeadlockDetectionTimeout());
755755

756756
// Assert: Cache is not evicted and all threads remain.
757757
assertEquals(4, threadPool.getActiveCount());
@@ -801,7 +801,7 @@ public void testRejectedExecutionError() {
801801
assertEquals("initial", status);
802802

803803
try {
804-
d.runUntilAllBlocked(DEFAULT_DEADLOCK_DETECTION_TIMEOUT);
804+
d.runUntilAllBlocked(getDeadlockDetectionTimeout());
805805
} catch (Throwable t) {
806806
assertTrue(t instanceof WorkflowRejectedExecutionError);
807807
}

0 commit comments

Comments
 (0)