Skip to main content
New to Testkube? Unleash the power of cloud native testing in Kubernetes with Testkube. Get Started >

Test Workflows - Matrix and Sharding

info

This Workflows functionality is not available when running the Testkube Agent in Standalone Mode - Read More

Often you want to run a test with multiple scenarios or environments, either to distribute the load or to verify it on different setup.

Test Workflows have a built-in mechanism for all these cases - both static and dynamic.

Usage

Matrix and sharding features are supported in Services (services), and both Test Suite (execute) and Parallel Steps (parallel) operations.

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")) }}'

Syntax

This feature allows you to provide few properties:

  • matrix to run the operation for different combinations
  • count/maxCount to replicate or distribute the operation
  • shards to 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.

Matrix

Matrix allows you to run the operation for multiple combinations. The values for each instance are accessible by matrix.<key>.

In example:

parallel:
matrix:
image: ['node:20', 'node:21', 'node:22']
memory: ['1Gi', '2Gi']
container:
resources:
requests:
memory: '{{ matrix.memory }}'
run:
image: '{{ matrix.image }}'

Will instantiate 6 copies:

indexmatrixIndexmatrix.imagematrix.memoryshardIndex
00"node:20""1Gi"0
11"node:20""2Gi"0
22"node:21""1Gi"0
33"node:21""2Gi"0
44"node:22""1Gi"0
55"node:22""2Gi"0

The matrix properties can be a static list of values, like:

matrix:
browser: [ 'chrome', 'firefox', '{{ config.another }}' ]

or could be dynamic one, using Test Workflow's expressions:

matrix:
files: 'glob("/data/repo/**/*.test.js")'

Sharding

Often you may want to distribute the load, to speed up the execution. To do so, you can use shards and count/maxCount properties.

  • shards is a map of data to split across different instances
  • count/maxCount are describing the number of instances to start
    • count defines static number of instances (always)
    • maxCount defines maximum number of instances (will be lower if there is not enough data in shards to split)
parallel:
count: 5
description: "{{ index + 1 }} instance of {{ count }}"
run:
image: grafana/k6:latest

__

Similarly to matrix, the shards may contain a static list, or Test Workflow's expression.

Counters

Besides having the matrix.<key> and shard.<key> there are some counter variables available in Test Workflow's expressions:

  • index and count - counters for total instances
  • matrixIndex and matrixCount - counters for the combinations
  • shardIndex and shardCount - counters for the shards

Matrix and sharding together

Sharding can be run along with matrix. In that case, for every matrix combination, we do have selected replicas/sharding. In example:

matrix:
browser: ["chrome", "firefox"]
memory: ["1Gi", "2Gi"]
count: 2
shards:
url: ["https://testkube.io", "https://docs.testkube.io", "https://app.testkube.io"]

Will start 8 instances:

indexmatrixIndexmatrix.browsermatrix.memoryshardIndexshard.url
00"chrome""1Gi"0["https://testkube.io", "https://docs.testkube.io"]
10"chrome""1Gi"1["https://app.testkube.io"]
21"chrome""2Gi"0["https://testkube.io", "https://docs.testkube.io"]
31"chrome""2Gi"1["https://app.testkube.io"]
42"firefox""1Gi"0["https://testkube.io", "https://docs.testkube.io"]
52"firefox""1Gi"1["https://app.testkube.io"]
63"firefox""2Gi"0["https://testkube.io", "https://docs.testkube.io"]
73"firefox""2Gi"1["https://app.testkube.io"]