Test Workflows - Matrix and Sharding
This Workflows functionality is not available when running the Testkube Runner in Standalone Mode - Read More
It is often desirable to run a test for multiple scenarios or environments, for example to distribute load or to verify your application for different input. This is traditionally achieved by defining configuration matrixes for each scenario and running all permutations.
Furthermore, it is common to split tests into multiple executions that run in parallel ("shards") to speed up the execution.
Test Workflows have built-in mechanisms for both these cases, using both static and dynamic configurations, which can further be combined with parallelisation to achieve highly efficient test executions.
Sharding (or parallel execution in general) usually only makes sense for long-lasting tests. In the case of small and/or short-lasting tests, sharding will often not decrease overall execution times.
Usage
Matrix and sharding features are supported in Services (services), and both Composite (execute)
and Parallel Step (parallel) operations.
- Services (
services) - Composite (
execute) - Parallel Steps (
parallel)
kind: TestWorkflow
apiVersion: testworkflows.testkube.io/v1
metadata:
name: example-matrix-services
spec:
services:
remote:
matrix:
browser:
- driver: chrome
image: selenium/standalone-chrome:4.21.0-20240517
- driver: edge
image: selenium/standalone-edge:4.21.0-20240517
- driver: firefox
image: selenium/standalone-firefox:4.21.0-20240517
image: "{{ matrix.browser.image }}"
description: "{{ matrix.browser.driver }}"
readinessProbe:
httpGet:
path: /wd/hub/status
port: 4444
periodSeconds: 1
steps:
- shell: 'echo {{ shellquote(join(map(services.remote, "tojson(_.value)"), "\n")) }}'
kind: TestWorkflow
apiVersion: testworkflows.testkube.io/v1
metadata:
name: example-matrix-test-suite
spec:
steps:
- execute:
workflows:
- name: k6-workflow-smoke
matrix:
target:
- https://testkube.io
- https://docs.testkube.io
config:
target: "{{ matrix.target }}"
apiVersion: testworkflows.testkube.io/v1
kind: TestWorkflow
metadata:
name: example-sharded-playwright
spec:
content:
git:
uri: https://github.com/kubeshop/testkube
paths:
- test/playwright/playwright-project
container:
image: mcr.microsoft.com/playwright:v1.32.3-focal
workingDir: /data/repo/test/playwright/playwright-project
steps:
- name: Install dependencies
shell: "npm ci"
- name: Run tests
parallel:
count: 2
transfer:
- from: /data/repo
shell: "npx playwright test --shard {{ index + 1 }}/{{ count }}"
Syntax
This feature allows you to provide few properties:
matrixto run the operation for different combinationscount/maxCountto replicate or distribute the operationshardsto provide the dataset to distribute among replicas
Both matrix and shards can be used together - all the sharding (shards + count/maxCount) will be replicated for each matrix combination.