Skip to content

Commit 91b75ee

Browse files
authored
[Improvement-17843][Master] Add IT case for task timeout alert (#18001)
1 parent 1df9f66 commit 91b75ee

3 files changed

Lines changed: 233 additions & 0 deletions

File tree

dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/integration/cases/WorkflowStartTestCase.java

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,4 +1861,107 @@ public void testWorkflowTimeout_WithAlertGroup_ShouldSendAlert() {
18611861

18621862
masterContainer.assertAllResourceReleased();
18631863
}
1864+
@Test
1865+
@DisplayName("Test start a workflow which contains a dep task with timeout warn strategy")
1866+
public void testStartWorkflow_withTimeoutWarnTask() {
1867+
masterConfig.getServerLoadProtection().setEnabled(false);
1868+
1869+
final String yaml = "/it/start/workflow_with_timeout_warn_task.yaml";
1870+
final WorkflowTestCaseContext context = workflowTestCaseContextFactory.initializeContextFromYaml(yaml);
1871+
final WorkflowDefinition workflow = context.getWorkflow("workflow_with_timeout_warn_task");
1872+
1873+
final WorkflowOperator.WorkflowTriggerDTO workflowTriggerDTO = WorkflowOperator.WorkflowTriggerDTO
1874+
.builder()
1875+
.workflowDefinition(workflow)
1876+
.runWorkflowCommandParam(new RunWorkflowCommandParam())
1877+
.warningGroupId(workflow.getWarningGroupId())
1878+
.build();
1879+
1880+
final Integer workflowInstanceId = workflowOperator.manualTriggerWorkflow(workflowTriggerDTO);
1881+
1882+
await()
1883+
.atMost(Duration.ofSeconds(90))
1884+
.untilAsserted(() -> {
1885+
Assertions
1886+
.assertThat(repository.queryWorkflowInstance(workflow))
1887+
.satisfiesExactly(workflowInstance -> assertThat(
1888+
workflowInstance.getState())
1889+
.isEqualTo(WorkflowExecutionStatus.RUNNING_EXECUTION));
1890+
1891+
Assertions
1892+
.assertThat(repository.queryTaskInstance(workflow))
1893+
.hasSize(1)
1894+
.satisfiesExactly(taskInstance -> {
1895+
assertThat(taskInstance.getName())
1896+
.isEqualTo("dep_task_with_timeout_warn");
1897+
assertThat(taskInstance.getState())
1898+
.isEqualTo(TaskExecutionStatus.RUNNING_EXECUTION);
1899+
});
1900+
1901+
Assertions
1902+
.assertThat(repository.queryAlert(workflowInstanceId))
1903+
.isNotEmpty()
1904+
.anySatisfy(alert -> {
1905+
assertThat(alert.getAlertType())
1906+
.isEqualTo(AlertType.TASK_TIMEOUT);
1907+
});
1908+
});
1909+
1910+
workflowOperator.stopWorkflowInstance(workflowInstanceId);
1911+
await()
1912+
.atMost(Duration.ofSeconds(30))
1913+
.untilAsserted(() -> Assertions.assertThat(repository.queryWorkflowInstance(workflowInstanceId))
1914+
.matches(w -> w.getState() == WorkflowExecutionStatus.STOP));
1915+
masterContainer.assertAllResourceReleased();
1916+
}
1917+
1918+
@Test
1919+
@DisplayName("Test start a workflow which contains a dep task with timeout warn failed strategy")
1920+
public void testStartWorkflow_withTimeoutWarnFailedTask() {
1921+
masterConfig.getServerLoadProtection().setEnabled(false);
1922+
1923+
final String yaml = "/it/start/workflow_with_timeout_warnfailed_task.yaml";
1924+
final WorkflowTestCaseContext context = workflowTestCaseContextFactory.initializeContextFromYaml(yaml);
1925+
final WorkflowDefinition workflow = context.getWorkflow("workflow_with_timeout_warnfailed_task");
1926+
1927+
final WorkflowOperator.WorkflowTriggerDTO workflowTriggerDTO = WorkflowOperator.WorkflowTriggerDTO
1928+
.builder()
1929+
.workflowDefinition(workflow)
1930+
.runWorkflowCommandParam(new RunWorkflowCommandParam())
1931+
.warningGroupId(workflow.getWarningGroupId())
1932+
.build();
1933+
1934+
final Integer workflowInstanceId = workflowOperator.manualTriggerWorkflow(workflowTriggerDTO);
1935+
1936+
await()
1937+
.atMost(Duration.ofSeconds(90))
1938+
.untilAsserted(() -> {
1939+
Assertions
1940+
.assertThat(repository.queryWorkflowInstance(workflow))
1941+
.satisfiesExactly(workflowInstance -> assertThat(
1942+
workflowInstance.getState())
1943+
.isEqualTo(WorkflowExecutionStatus.STOP));
1944+
1945+
Assertions
1946+
.assertThat(repository.queryTaskInstance(workflow))
1947+
.hasSize(1)
1948+
.satisfiesExactly(taskInstance -> {
1949+
assertThat(taskInstance.getName())
1950+
.isEqualTo("dep_task_with_timeout_warnfailed");
1951+
assertThat(taskInstance.getState())
1952+
.isEqualTo(TaskExecutionStatus.KILL);
1953+
});
1954+
1955+
Assertions
1956+
.assertThat(repository.queryAlert(workflowInstanceId))
1957+
.isNotEmpty()
1958+
.anySatisfy(alert -> {
1959+
assertThat(alert.getAlertType())
1960+
.isEqualTo(AlertType.TASK_TIMEOUT);
1961+
});
1962+
});
1963+
1964+
masterContainer.assertAllResourceReleased();
1965+
}
1966+
18641967
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
project:
19+
name: MasterIntegrationTest
20+
code: 1
21+
description: This is a fake project
22+
userId: 1
23+
userName: admin
24+
createTime: 2024-08-12 00:00:00
25+
updateTime: 2021-08-12 00:00:00
26+
27+
workflows:
28+
- name: workflow_with_timeout_warn_task
29+
code: 1
30+
version: 1
31+
projectCode: 1
32+
description: This is a fake workflow with single timeout warn task
33+
releaseState: ONLINE
34+
warningGroupId: 1
35+
createTime: 2024-08-12 00:00:00
36+
updateTime: 2021-08-12 00:00:00
37+
userId: 1
38+
executionType: PARALLEL
39+
40+
tasks:
41+
- name: dep_task_with_timeout_warn
42+
code: 1
43+
version: 1
44+
projectCode: 1
45+
userId: 1
46+
timeoutFlag: 'OPEN'
47+
timeoutNotifyStrategy: 'WARN'
48+
timeout: 1
49+
taskType: DEPENDENT
50+
taskParams: '{"localParams":[],"resourceList":[],"dependence":{"checkInterval":10,"failurePolicy":"DEPENDENT_FAILURE_FAILURE","relation":"AND","dependTaskList":[{"relation":"AND","dependItemList":[{"dependentType":"DEPENDENT_ON_WORKFLOW","projectCode":1,"definitionCode":1,"depTaskCode":0,"cycle":"day","dateValue":"last1Days"}]}]}}'
51+
workerGroup: default
52+
createTime: 2024-08-12 00:00:00
53+
updateTime: 2021-08-12 00:00:00
54+
taskExecuteType: BATCH
55+
56+
taskRelations:
57+
- projectCode: 1
58+
workflowDefinitionCode: 1
59+
workflowDefinitionVersion: 1
60+
preTaskCode: 0
61+
preTaskVersion: 0
62+
postTaskCode: 1
63+
postTaskVersion: 1
64+
createTime: 2024-08-12 00:00:00
65+
updateTime: 2024-08-12 00:00:00
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
project:
19+
name: MasterIntegrationTest
20+
code: 1
21+
description: This is a fake project
22+
userId: 1
23+
userName: admin
24+
createTime: 2024-08-12 00:00:00
25+
updateTime: 2021-08-12 00:00:00
26+
27+
workflows:
28+
- name: workflow_with_timeout_warnfailed_task
29+
code: 1
30+
version: 1
31+
projectCode: 1
32+
description: This is a fake workflow with single timeout warnfailed task
33+
releaseState: ONLINE
34+
warningGroupId: 1
35+
createTime: 2024-08-12 00:00:00
36+
updateTime: 2021-08-12 00:00:00
37+
userId: 1
38+
executionType: PARALLEL
39+
40+
tasks:
41+
- name: dep_task_with_timeout_warnfailed
42+
code: 1
43+
version: 1
44+
projectCode: 1
45+
userId: 1
46+
timeoutFlag: 'OPEN'
47+
timeoutNotifyStrategy: 'WARNFAILED'
48+
timeout: 1
49+
taskType: DEPENDENT
50+
taskParams: '{"localParams":[],"resourceList":[],"dependence":{"checkInterval":10,"failurePolicy":"DEPENDENT_FAILURE_FAILURE","relation":"AND","dependTaskList":[{"relation":"AND","dependItemList":[{"dependentType":"DEPENDENT_ON_WORKFLOW","projectCode":1,"definitionCode":1,"depTaskCode":0,"cycle":"day","dateValue":"last1Days"}]}]}}'
51+
workerGroup: default
52+
createTime: 2024-08-12 00:00:00
53+
updateTime: 2021-08-12 00:00:00
54+
taskExecuteType: BATCH
55+
56+
taskRelations:
57+
- projectCode: 1
58+
workflowDefinitionCode: 1
59+
workflowDefinitionVersion: 1
60+
preTaskCode: 0
61+
preTaskVersion: 0
62+
postTaskCode: 1
63+
postTaskVersion: 1
64+
createTime: 2024-08-12 00:00:00
65+
updateTime: 2024-08-12 00:00:00

0 commit comments

Comments
 (0)