Skip to content

Commit 6a16297

Browse files
committed
1570 Increase TimeUnit.SECONDS.sleep duration in TaskWorkerTest for improved test stability; add future cancellation on timeout in TaskWorker.
1 parent e39a414 commit 6a16297

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

server/libs/atlas/atlas-worker/atlas-worker-impl/src/main/java/com/bytechef/atlas/worker/TaskWorker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ public void onTaskExecutionEvent(TaskExecutionEvent taskExecutionEvent) {
146146
try {
147147
future.get(calculateTimeout(taskExecution), TimeUnit.MILLISECONDS);
148148
} catch (InterruptedException | ExecutionException | TimeoutException e) {
149+
future.cancel(true);
150+
149151
handleException(taskExecution, e);
150152
} catch (CancellationException e) {
151153
logger.debug("Cancelled task: {}", taskExecution.getId());

server/libs/atlas/atlas-worker/atlas-worker-impl/src/test/java/com/bytechef/atlas/worker/TaskWorkerTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ public void test6() throws InterruptedException {
364364
executorService.submit(() -> worker.onTaskExecutionEvent(new TaskExecutionEvent(taskExecution)));
365365

366366
// give it a second to start executing
367-
TimeUnit.SECONDS.sleep(1);
367+
TimeUnit.SECONDS.sleep(2);
368368

369369
Assertions.assertEquals(1, MapUtils.size(worker.getTaskExecutions()));
370370

@@ -374,7 +374,7 @@ public void test6() throws InterruptedException {
374374
Validate.notNull(taskExecution.getJobId(), "jobId"), Validate.notNull(taskExecution.getId(), "id"))));
375375

376376
// give it a second to cancel
377-
TimeUnit.SECONDS.sleep(1);
377+
TimeUnit.SECONDS.sleep(2);
378378

379379
Assertions.assertEquals(0, MapUtils.size(worker.getTaskExecutions()));
380380
}
@@ -420,7 +420,7 @@ public void test7() throws InterruptedException {
420420
EXECUTOR_SERVICE.submit(() -> worker.onTaskExecutionEvent(new TaskExecutionEvent(taskExecution2)));
421421

422422
// give it a second to start executing
423-
TimeUnit.SECONDS.sleep(1);
423+
TimeUnit.SECONDS.sleep(2);
424424

425425
Assertions.assertEquals(2, MapUtils.size(worker.getTaskExecutions()));
426426

@@ -430,7 +430,7 @@ public void test7() throws InterruptedException {
430430
Validate.notNull(taskExecution1.getJobId(), "jobId"), Validate.notNull(taskExecution1.getId(), "id"))));
431431

432432
// give it a second to cancel
433-
TimeUnit.SECONDS.sleep(1);
433+
TimeUnit.SECONDS.sleep(2);
434434

435435
Assertions.assertEquals(1, MapUtils.size(worker.getTaskExecutions()));
436436
}
@@ -477,7 +477,7 @@ public void test8() throws InterruptedException {
477477
EXECUTOR_SERVICE.submit(() -> worker.onTaskExecutionEvent(new TaskExecutionEvent(taskExecution2)));
478478

479479
// give it a second to start executing
480-
TimeUnit.SECONDS.sleep(1);
480+
TimeUnit.SECONDS.sleep(2);
481481

482482
Assertions.assertEquals(2, MapUtils.size(worker.getTaskExecutions()));
483483

@@ -487,7 +487,7 @@ public void test8() throws InterruptedException {
487487
Validate.notNull(taskExecution1.getJobId(), "jobId"), Validate.notNull(taskExecution1.getId(), "id"))));
488488

489489
// give it a second to cancel
490-
TimeUnit.SECONDS.sleep(1);
490+
TimeUnit.SECONDS.sleep(2);
491491

492492
Assertions.assertEquals(0, MapUtils.size(worker.getTaskExecutions()));
493493
}

0 commit comments

Comments
 (0)