Integration test stages in Jenkins - Time & Space Complexity
We want to understand how the time taken by integration test stages grows as we add more tests.
How does running more tests affect the total time Jenkins spends?
Analyze the time complexity of the following Jenkins pipeline snippet.
pipeline {
agent any
stages {
stage('Integration Tests') {
steps {
script {
def tests = ['test1', 'test2', 'test3', 'testN']
for (test in tests) {
sh "run-integration-test ${test}"
}
}
}
}
}
}
This code runs a list of integration tests one by one in a loop.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Loop over the list of tests to run each test command.
- How many times: Once for each test in the list (n times).
As the number of tests increases, the total time grows roughly in direct proportion.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 test runs |
| 100 | 100 test runs |
| 1000 | 1000 test runs |
Pattern observation: Doubling the number of tests roughly doubles the total execution time.
Time Complexity: O(n)
This means the total time grows linearly with the number of integration tests.
[X] Wrong: "Running tests in a loop means the time stays the same no matter how many tests there are."
[OK] Correct: Each test runs separately, so more tests add more time, not the same time.
Understanding how test stages scale helps you design pipelines that run efficiently as projects grow.
What if we ran all tests in parallel instead of a loop? How would the time complexity change?