Skip to content

Commit ccfb368

Browse files
Concurrent poll request lock test fix (#2187)
Hopefully make concurrentPollRequestLockTest less flakey
1 parent 1d668c6 commit ccfb368

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

temporal-sdk/src/test/java/io/temporal/internal/worker/WorkflowWorkerTest.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import io.temporal.internal.replay.ReplayWorkflowFactory;
4141
import io.temporal.internal.replay.ReplayWorkflowTaskHandler;
4242
import io.temporal.serviceclient.WorkflowServiceStubs;
43+
import io.temporal.testUtils.Eventually;
4344
import io.temporal.testUtils.HistoryUtils;
4445
import io.temporal.worker.MetricsType;
4546
import io.temporal.worker.tuning.FixedSizeSlotSupplier;
@@ -192,27 +193,32 @@ public void concurrentPollRequestLockTest() throws Exception {
192193
pollTaskQueueLatch.await();
193194
// Wait until the worker handles at least one WFT
194195
handleTaskLatch.await();
195-
// Sleep to allow metrics to be published
196-
Thread.sleep(100);
197-
// Since all polls have the same runID only one should get through, the other two should be
198-
// blocked
199-
assertEquals(runLockManager.totalLocks(), 1);
200196
// Verify 3 slots have been used
201-
reporter.assertGauge(
202-
MetricsType.WORKER_TASK_SLOTS_AVAILABLE,
203-
ImmutableMap.of("worker_type", "WorkflowWorker"),
204-
97.0);
197+
Eventually.assertEventually(
198+
Duration.ofSeconds(10),
199+
() -> {
200+
// Since all polls have the same runID only one should get through, the other two should
201+
// be
202+
// blocked
203+
assertEquals(runLockManager.totalLocks(), 1);
204+
reporter.assertGauge(
205+
MetricsType.WORKER_TASK_SLOTS_AVAILABLE,
206+
ImmutableMap.of("worker_type", "WorkflowWorker"),
207+
97.0);
208+
});
205209
// Wait for the worker to respond, by this time the other blocked tasks should have timed out
206210
respondTaskLatch.await();
207-
// Sleep to allow metrics to be published
208-
Thread.sleep(100);
209-
// No task should have the lock anymore
210-
assertEquals(runLockManager.totalLocks(), 0);
211211
// All slots should be available
212-
reporter.assertGauge(
213-
MetricsType.WORKER_TASK_SLOTS_AVAILABLE,
214-
ImmutableMap.of("worker_type", "WorkflowWorker"),
215-
100.0);
212+
Eventually.assertEventually(
213+
Duration.ofSeconds(10),
214+
() -> {
215+
// No task should have the lock anymore
216+
assertEquals(runLockManager.totalLocks(), 0);
217+
reporter.assertGauge(
218+
MetricsType.WORKER_TASK_SLOTS_AVAILABLE,
219+
ImmutableMap.of("worker_type", "WorkflowWorker"),
220+
100.0);
221+
});
216222
// Cleanup
217223
worker.shutdown(new ShutdownManager(), false).get();
218224
// Verify we only handled two tasks

0 commit comments

Comments
 (0)