Skip to content

WDL for testing individual task failures? #179

@sckott

Description

@sckott

We have a few WDLs for testing a whole WDL fails either womtool validation or cromwell run, but I don't think we have one for focusing on individual tasks failing and making sure we deal with that behavior.

@tefirman @sitapriyamoorthi

Thoughts on this? Please improve!

version 1.0

workflow TestWorkflowWithFailure {
    input {
        String sample_name = "test_sample"
        Boolean should_fail_task = true
    }

    call SuccessfulTask1 { input: sample_name = sample_name }

    call SuccessfulTask2 { input: sample_name = sample_name }

    call FailingTask { input:
        sample_name = sample_name,
        should_fail = should_fail_task,
    }

    call SuccessfulTask3 { input: sample_name = sample_name }

    output {
        String task1_result = SuccessfulTask1.result
        String task2_result = SuccessfulTask2.result
        String task3_result = SuccessfulTask3.result
        String? task_result_fail = FailingTask.result
    }
}

task SuccessfulTask1 {
    input {
        String sample_name
    }

    command <<<
        echo "Task 1 processing sample: ${sample_name}"
        echo "Task 1 completed successfully" > result.txt
        sleep 2
    >>>

    output {
        String result = read_string("result.txt")
    }

    runtime {
        docker: "ubuntu:20.04"
        memory: "1 GB"
        cpu: 1
    }
}

task SuccessfulTask2 {
    input {
        String sample_name
    }

    command <<<
        echo "Task 2 processing sample: ${sample_name}"
        mkdir -p output
        echo "Task 2: Analysis complete" > output/analysis.txt
        ls -la output/
    >>>

    output {
        String result = read_string("output/analysis.txt")
    }

    runtime {
        docker: "ubuntu:20.04"
        memory: "1 GB"
        cpu: 1
    }
}

task FailingTask {
    input {
        String sample_name
        Boolean should_fail = true
    }

    command <<<
        echo "Starting failing task for sample: ${sample_name}"
        echo "should_fail parameter value: ${should_fail}"

        if [[ ~{should_fail} == "true" ]]; then
            echo "This task is designed to fail for testing purposes"
            echo "Simulating error condition..."
            sleep 1
            echo "FAILURE: Task failed as intended" >&2
            exit 1  # This will cause the task to fail
        else
            echo "Task configured to succeed"
            echo "Success" > result.txt
        fi
    >>>

    output {
        String? result = read_string("result.txt")
    }

    runtime {
        docker: "ubuntu:20.04"
        memory: "1 GB"
        cpu: 1
    }
}

task SuccessfulTask3 {
    input {
        String sample_name
    }

    command <<<
        echo "Task 3 processing sample: ${sample_name}"
        echo "Generating final report..."
        echo "Report generated for ${sample_name}" > final_report.txt
        cat final_report.txt
    >>>

    output {
        String result = read_string("final_report.txt")
    }

    runtime {
        docker: "ubuntu:20.04"
        memory: "1 GB"
        cpu: 1
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    unit testAdding or modifying a unit test

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions