Monk CIMonk CI home

20 Nov, 2026Mahesh Kale

Parallel Tests in GitHub Actions: Speed vs Cost


Use GitHub Actions matrix jobs and test shards on Monk CI to shorten feedback time while tracking repeated setup, runner minutes, and cost.

Four test jobs can finish sooner than one. They can also run the same suite four times, consume more compute, and leave you with no faster answer.

The difference is test selection. A GitHub Actions matrix creates jobs. A test runner's sharding feature gives each job a different slice of work. On Monk CI, you can combine both while keeping an eye on total runner time.

A matrix doesn't divide your tests

An entry such as shard: [1, 2, 3, 4] creates four job variants. Unless the test command uses that value, each variant runs the full suite.

Node's built-in test runner accepts --test-shard=index/total. It divides test files among shards. That last detail matters: a single slow file won't become four balanced pieces merely because you launch four jobs.

For this example, set package.json to use "test": "node --test". The supplied demo has four test files so you can try the split locally.

Give each job a distinct slice

Use this workflow for a repository with a root npm lockfile:

name: Sharded tests
on:
  push:
  pull_request:

permissions:
  contents: read

jobs:
  test:
    runs-on: monkci-ubuntu-24.04-4
    strategy:
      fail-fast: false
      max-parallel: 4
      matrix:
        shard: [1, 2, 3, 4]
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: '24'
          cache: npm
      - run: npm ci
      - name: Run this shard
        shell: bash
        run: |
          npm test -- --test-shard=${{ matrix.shard }}/4 2>&1 | tee test-output.log
      - uses: actions/upload-artifact@v7
        if: ${{ !cancelled() }}
        with:
          name: test-log-${{ matrix.shard }}
          path: test-output.log

As with the Node.js build workflow, these action versions need a runner that supports their Node 24 runtime. The explicit Monk CI label keeps machine size consistent across shards.

max-parallel caps concurrent matrix jobs; it doesn't reserve four runners. fail-fast: false lets other shards continue after one fails, which can give you a fuller failure report at the cost of more work.

Give each shard a visible result in your pull request checks. If a deployment depends on the tests, make it wait for every required shard, so one passing job cannot hide a slower failing job.

Each log gets a unique artifact name. The explicit Bash shell preserves a failed test's exit status through the pipe to tee, so saving output doesn't turn a failing shard green.

Faster feedback can use more compute

Here's a simple model, not measured Monk CI performance or pricing. Assume ready capacity, balanced shards, no retries, and one minute of setup per job.

An illustrative serial job takes 13 minutes and 13 runner-minutes; four balanced jobs finish in four minutes but total 16 runner-minutes.
An illustrative serial job takes 13 minutes and 13 runner-minutes; four balanced jobs finish in four minutes but total 16 runner-minutes.
LayoutSetup per jobTests per jobCompletion timeTotal runner-minutes
One job1 minute12 minutes13 minutes13
Four shards1 minute3 minutes4 minutes16

Setup repeats four times. The slower shard sets the completion time, while all four jobs contribute to total compute. Real bills also depend on machine rates, allowances, and billing rules; runner-minutes alone aren't a price quote.

Find the split that earns its keep

Start with two shards, then try four. Compare completion time, summed job duration, queue delay, and failure rate. Watch for uneven test files and extra pressure on a shared database or test service.

Keep test data independent between shards. Also check worker counts inside each job: four jobs with many local workers can overload small machines or a shared service. Adding two Node versions to a four-shard matrix creates eight jobs, not four.

Takeaway: Use matrix to launch jobs and sharding to divide tests. Keep the split that improves feedback enough to justify the extra setup and compute.

Sources

Try Monk CI for free

Continue with GitHub