@Test
public void testCheckWorkflowTimeout() {

    Counter counter = registry.counter("workflow_failure", "class", "WorkflowMonitor", "workflowName", "test",
        "status", "TIMED_OUT", "ownerApp", "junit");
    assertEquals(0, counter.count());
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("test");
    Workflow workflow = new Workflow();
    workflow.setOwnerApp("junit");
    workflow.setStartTime(System.currentTimeMillis() - 10_000);
    workflow.setWorkflowId("workflow_id");
    // no-op
    workflow.setWorkflowDefinition(null);
    deciderService.checkWorkflowTimeout(workflow);
    // no-op
    workflow.setWorkflowDefinition(workflowDef);
    deciderService.checkWorkflowTimeout(workflow);
    // alert
    workflowDef.setTimeoutPolicy(WorkflowDef.TimeoutPolicy.ALERT_ONLY);
    workflowDef.setTimeoutSeconds(2);
    workflow.setWorkflowDefinition(workflowDef);
    deciderService.checkWorkflowTimeout(workflow);
    assertEquals(1, counter.count());
    // time out
    workflowDef.setTimeoutPolicy(WorkflowDef.TimeoutPolicy.TIME_OUT_WF);
    workflow.setWorkflowDefinition(workflowDef);
    try {
        deciderService.checkWorkflowTimeout(workflow);
    } catch (TerminateWorkflowException twe) {
        assertTrue(twe.getMessage().contains("Workflow 'workflow_id' timed out"));
    }
    // for a retried workflow
    workflow.setLastRetriedTime(System.currentTimeMillis() - 5_000);
    try {
        deciderService.checkWorkflowTimeout(workflow);
    } catch (TerminateWorkflowException twe) {
        assertTrue(twe.getMessage().contains("Workflow 'workflow_id' timed out"));
    }
}