Skip to content

Commit 3666604

Browse files
author
Yang Guo
committed
fix unit test for job timeout
1 parent 984e9dc commit 3666604

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

config/app-api.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ system.email = [email protected]
2929
system.username = admin
3030
system.password = 123456
3131

32-
task.job.toggle.execution_timeout = false
33-
## 6s expire job
34-
task.job.toggle.execution_create_session_duration = 600
35-
## 1h expire job
32+
task.job.toggle.execution_timeout = true
33+
## expired in 1800 seconds for create session
34+
task.job.toggle.execution_create_session_duration = 1800
35+
## expired in 3600 seconds for job running
3636
task.job.toggle.execution_running_duration = 3600

platform-api/src/main/java/com/flow/platform/api/service/job/JobServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,14 @@ public void checkTimeoutTask() {
662662

663663
LOGGER.trace("job timeout task start");
664664

665-
// create session job timeout 6s time out
665+
// job timeout on create session
666666
ZonedDateTime finishZoneDateTime = ZonedDateTime.now().minusSeconds(jobExecuteTimeoutCreateSessionDuration);
667667
List<Job> jobs = jobDao.listForExpired(finishZoneDateTime, JobStatus.SESSION_CREATING);
668668
for (Job job : jobs) {
669669
updateJobAndNodeResultTimeout(job);
670670
}
671671

672-
// running job timeout 1h time out
672+
// job timeout on running
673673
ZonedDateTime finishRunningZoneDateTime = ZonedDateTime.now().minusSeconds(jobExecuteTimeoutRunningDuration);
674674
List<Job> runningJobs = jobDao.listForExpired(finishRunningZoneDateTime, JobStatus.RUNNING);
675675
for (Job job : runningJobs) {

platform-api/src/main/resources/app-default.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ system.email = [email protected]
2929
system.username = admin
3030
system.password = 123456
3131

32-
task.job.toggle.execution_timeout = false
33-
## 6s expire job
34-
task.job.toggle.execution_create_session_duration = 600
35-
## 1h expire job
32+
task.job.toggle.execution_timeout = true
33+
## expired in 1800 seconds for job create session
34+
task.job.toggle.execution_create_session_duration = 1800
35+
## expired in 3600 seconds for running job
3636
task.job.toggle.execution_running_duration = 3600
3737

platform-api/src/test/java/com/flow/platform/api/test/service/JobServiceTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.flow.platform.api.test.TestBase;
3333
import com.flow.platform.api.util.CommonUtil;
3434
import com.flow.platform.core.exception.IllegalStatusException;
35+
import com.flow.platform.core.util.ThreadUtil;
3536
import com.flow.platform.domain.Cmd;
3637
import com.flow.platform.domain.CmdResult;
3738
import com.flow.platform.domain.CmdStatus;
@@ -260,19 +261,16 @@ public void should_stop_running_job_success() throws IOException {
260261
Assert.assertEquals(NodeStatus.STOPPED, stoppedJob.getRootResult().getStatus());
261262
}
262263

263-
264264
@Test
265265
public void should_job_time_out_and_reject_callback() throws IOException, InterruptedException {
266+
// given: job and mock updated time as expired
266267
Node rootForFlow = createRootFlow("flow1", "demo_flow2.yaml");
267-
268268
Job job = jobService.createFromFlowYml(rootForFlow.getPath(), JobCategory.TAG, null, mockUser);
269-
270269
Assert.assertNotNull(job.getEnv("FLOW_WORKSPACE"));
271270
Assert.assertNotNull(job.getEnv("FLOW_VERSION"));
272271

273-
Thread.sleep(7000);
274-
275272
// when: check job timeout
273+
ThreadUtil.sleep(20000);
276274
jobService.checkTimeoutTask();
277275

278276
// then: job status should be timeout

0 commit comments

Comments
 (0)