Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .github/workflows/nethermind-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ env:

jobs:
tests:
name: Run ${{ matrix.project }}
name: Run ${{ matrix.project }}${{ matrix.chunk && format(' ({0})', matrix.chunk) || '' }}
runs-on: ubuntu-latest
continue-on-error: true
outputs:
Expand All @@ -40,7 +40,6 @@ jobs:
- Ethereum.KeyAddress.Test
- Ethereum.KeyStore.Test
- Ethereum.Legacy.Blockchain.Block.Test
- Ethereum.Legacy.Blockchain.Test
- Ethereum.Legacy.Transition.Test
- Ethereum.Legacy.VM.Test
- Ethereum.PoW.Test
Expand Down Expand Up @@ -91,6 +90,16 @@ jobs:
- Nethermind.TxPool.Test
- Nethermind.Wallet.Test
- Nethermind.Xdc.Test
chunk: ['']
include:
- project: Ethereum.Legacy.Blockchain.Test
chunk: 1of4
- project: Ethereum.Legacy.Blockchain.Test
chunk: 2of4
- project: Ethereum.Legacy.Blockchain.Test
chunk: 3of4
- project: Ethereum.Legacy.Blockchain.Test
chunk: 4of4
steps:
- name: Check out repository
uses: actions/checkout@v6
Expand All @@ -103,6 +112,8 @@ jobs:
- name: ${{ matrix.project }}
id: test
working-directory: src/Nethermind/${{ matrix.project }}
env:
TEST_CHUNK: ${{ matrix.chunk }}
run: |
dotnet test --project ${{ matrix.project }}.csproj -c release \
${{ env.COLLECT_COVERAGE == 'true' && '--coverage --coverage-output-format cobertura --coverage-settings $GITHUB_WORKSPACE/src/Nethermind/codecoverage.config' || '' }}
Expand All @@ -115,15 +126,15 @@ jobs:
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.project }}-outcome
name: ${{ matrix.project }}${{ matrix.chunk && format('-{0}', matrix.chunk) || '' }}-outcome
path: test.outcome
retention-days: 1

- name: Upload coverage report
if: env.COLLECT_COVERAGE == 'true'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.project }}-coverage
name: ${{ matrix.project }}${{ matrix.chunk && format('-{0}', matrix.chunk) || '' }}-coverage
path: src/Nethermind/artifacts/bin/${{ matrix.project }}/release/TestResults/*.cobertura.xml
retention-days: 1

Expand Down
60 changes: 60 additions & 0 deletions src/Nethermind/Ethereum.Test.Base/TestChunkFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using System.Linq;

namespace Ethereum.Test.Base;

/// <summary>
/// Filters tests into chunks for parallel CI execution.
/// Set TEST_CHUNK environment variable to "1of3", "2of3", "3of3" etc.
/// Partitions tests by index for consistent and even distribution.
/// </summary>
public static class TestChunkFilter
{
public static IEnumerable<T> FilterByChunk<T>(IEnumerable<T> tests)
{
(int Index, int Total)? chunkConfig = GetChunkConfig();

if (chunkConfig is null)
{
return tests;
}

ICollection<T> testList = tests as ICollection<T> ?? [.. tests];
(int chunkIndex, int totalChunks) = chunkConfig.Value;

int count = testList.Count;
int chunkSize = count / totalChunks;
int remainder = count % totalChunks;

int skip = (chunkIndex - 1) * chunkSize;
int take = chunkSize + (chunkIndex == totalChunks ? remainder : 0);

return testList.Skip(skip).Take(take);

static (int Index, int Total)? GetChunkConfig()
{
string? chunkEnv = Environment.GetEnvironmentVariable("TEST_CHUNK");

if (string.IsNullOrEmpty(chunkEnv))
{
return null;
}

string[] parts = chunkEnv.Split("of", StringSplitOptions.None);

if (parts.Length != 2 ||
!int.TryParse(parts[0], out int index) ||
!int.TryParse(parts[1], out int total) ||
index < 1 || index > total || total < 1)
{
throw new ArgumentException($"Invalid TEST_CHUNK format: '{chunkEnv}'. Expected format: '1of3', '2of5', etc.");
}

return (index, total);
}
}
}
7 changes: 5 additions & 2 deletions src/Nethermind/Ethereum.Test.Base/TestsSourceLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ public TestsSourceLoader(ITestLoadStrategy testLoadStrategy, string path, string

public IEnumerable<EthereumTest> LoadTests()
{
return _testLoadStrategy.Load(_path, _wildcard);
IEnumerable<EthereumTest> tests = _testLoadStrategy.Load(_path, _wildcard);
return TestChunkFilter.FilterByChunk(tests);
}

public IEnumerable<TTestType> LoadTests<TTestType>()
where TTestType : EthereumTest
{
return _testLoadStrategy.Load(_path, _wildcard).Cast<TTestType>();
IEnumerable<TTestType> tests = _testLoadStrategy.Load(_path, _wildcard).Cast<TTestType>();
return TestChunkFilter.FilterByChunk(tests);
}
}
}