Enable parallelism on a Run Tests step
You can enable parallelism on a Run Tests step.
While the Run Tests step remains backwards compatible until removal, Harness recommends using the new Test step as soon as possible to take advanced of improved functionality and avoid service interruptions upon removal of the deprecated step.
To enable parallelism/test splitting in the Test step, refer to the Test step documentation.
By default, Test Intelligence reduces test time by running only the necessary tests to validate your code changes. You can enable parallelism and test splitting in your Run Tests steps to further optimize test times.
DOES THIS TOPIC APPLY TO YOU?
This topic explains test splitting/parallelism in Run Tests steps only.
For test splitting/parallelism in Run steps, go to Split tests in Run steps.
For test splitting/parallelism in Test steps, go to the Test step documentation.
With parallelism, you specify how you want Harness to divide similar workloads. When you use parallelism and test splitting with Test Intelligence, Harness divides the work after test selection. This means that your test execution time is reduced by both test selection and parallelism.
Note that while parallelism for TI can improve the total time it takes to run all tests, some tests may still take a long time to run if, by their nature, they are intensive, long-running tests.
Enable test splitting for TI
To enable test splitting for TI, you must:
Define a parallelism strategy
In the context of test splitting, the parallelism strategy defines the number of workloads into which tests can be divided. Each parallel instance (or workload) is a duplicate of the stage where you've defined a parallelism strategy, but each instance runs different tests.
Define the parallelism strategy on the stage with the Run Tests step.
You can configure parallelism strategies on stages or steps.
Harness recommends using stage-level parallelism for test splitting.
If you use step-level parallelism, you must ensure that your test runners won't interfere with each other because all parallel steps work in the same directory.
In your pipeline, select the stage where your tests run, and then select the Advanced tab.
Under Looping Strategies, select Parallelism.
Set the
parallelismvalue to the number of workloads that you want to divide your tests into. For example, if you want to create four workloads, setparallelism: 4.Optional: Define
maxConcurrency. This is a strategy to optimize parallelism.
Define the parallelism strategy (strategy.parallelism) on the stage with the RunTests step.
You can configure parallelism strategies on stages or steps.
Harness recommends using stage-level parallelism for test splitting.
If you use step-level parallelism, you must ensure that your test runners won't interfere with each other because all parallel steps work in the same directory.
Optimize parallelism
In general, a higher parallelism value means a faster pipeline run time, because the tests can be divided into more parallel instances. However, this depends on your test suite and resource limitations in your build infrastructure. For example, if you try to run 10 groups of tests, but your build infrastructure can't handle 10 parallel instances, the pipeline can fail or take longer than expected.
To optimize your parallelism strategy:
Try different parallelism values to determine your infrastructure's limits. Parallelism impacts resource allocation for the pipeline. A pipeline with five sequential stages can require fewer resources than a pipeline running five parallel instances of a stage, because the second pipeline has to run all five instances at once.
Use
maxConcurrencyto control the flow of parallel instances and avoid overtaxing infrastructure resources. Concurrency limits the number of parallel instances that can run at once and queues additional instances.For example, if you set
parallelism: 12, Harness attempts to run 12 instances of the stage at once. If you setparallelism: 12andmaxConcurrency: 3, Harness generates 12 instances of the stage, but only runs three instances at a time. The remaining nine instances are queued, and the queued instances start running as space clears in the concurrency limit (when prior instances finish).Concurrency allows you to divide tests into more workloads without overloading your system resources.
There are resource requirements to generate parallel instances (even if they are not all running at the same time) and handle queues. Try different combinations of
parallelismandmaxConcurrencyvalues to determine your ideal configuration.
Review the Best practices for looping strategies, including how to calculate ideal concurrency.
Enable Test Splitting on the Run Tests step
On the Run Tests step, set Enable Test Splitting (enableTestSplitting: true).
The Test Split Strategy is optional. The default test split strategy is class timing. If you would rather split tests by test count, you can set the Test Split Strategy to Test Count.
Class timing uses test times from previous runs to determine how to split the test workload for the current build. Test count uses simple division to split the tests into workloads. However, the maximum possible number of workloads is determined by the parallelism strategy you specified on the step or stage. For example, if you set parallelism: 5, then the tests are split into a maximum of five workloads.
Differentiate report names
With stage-level parallelism, results files are automatically output as separate stage artifacts.
If you want the individual results files to have unique names, you can use an expression or variable in the results file name, such as result_<+strategy.iteration>.xml or result_${HARNESS_NODE_INDEX}.xml.
You might need to modify your test tool configurations to support this report naming convention, and you must modify the Report Paths (reports.paths) value to include the Harness expression, such as <+strategy.iteration>. For example:
Harness recommends stage-level parallelism for test splitting. However, if you defined the parallelism strategy on a step (instead of a stage), you must use an expression or variable in the results file name, such as result_<+strategy.iteration>.xml or result_${HARNESS_NODE_INDEX}.xml, to ensure each parallel instance produces a uniquely-named results file. If you don't use an expression or variable in the results file name, the files overwrite each other or fail due to same-name conflicts. How you enable this varies by language and test tool. For this reason, among others, Harness recommends using stage-level parallelism for test splitting.
Differentiate parallel runs in logs
You can also use environment variables and expressions to differentiate parallel runs in build logs.
Add two stage variables:
HARNESS_STAGE_INDEX: <+strategy.iteration>- This is the index of the current parallel run.HARNESS_STAGE_TOTAL: <+strategy.iterations>- This is the total parallel runs.
Add a
preCommandto echo the variables' values so you can easily see the values in build logs.
YAML example: Test splitting for TI
This example shows a stage that uses Harness Cloud build infrastructure and runs Test Intelligence on a Java codebase. The parallelism strategy is set at the stage level.
Last updated
Was this helpful?