ByteSync icon indicating copy to clipboard operation
ByteSync copied to clipboard

[test] Reduce long-running non-integration test execution time

Open paul-fresquet opened this issue 8 months ago • 0 comments

Context

Non-integration automated tests are currently too slow to run frequently during local development and PR validation.

A recent measurement (excluding integration test projects) shows that the runtime is dominated by ByteSync.Client.UnitTests.

Scope

This issue focuses only on non-integration tests:

  • tests/ByteSync.Client.UnitTests
  • tests/ByteSync.ServerCommon.Tests
  • tests/ByteSync.Functions.UnitTests
  • tests/ByteSync.Common.Tests

Integration tests are explicitly out of scope.

Current Baseline (non-integration)

  • ByteSync.Client.UnitTests: ~112s (1133 tests)
  • ByteSync.ServerCommon.Tests: ~5.6s (245 tests)
  • ByteSync.Functions.UnitTests: ~0.36s (41 tests)
  • ByteSync.Common.Tests: ~0.19s (53 tests)

Priority Tests / Classes To Optimize First

  1. ByteSync.Client.UnitTests.TestUtilities.Mine.TestRsa
  • Test1_SameMessages (~9.1s)
  • Test1_EncryptedMessageNonUnicity (~7.1s)
  • Test1_DifferentMessages (~7.0s)
  • Test1_PublicKeyUnicity (~6.9s)
  1. ByteSync.Client.UnitTests.Services.TimeTracking.TimeTrackingComputerTests
  • Class total: ~31.7s across 22 tests
  • Several tests between ~1.0s and ~3.7s
  1. ByteSync.Client.UnitTests.Services.Communications.ConnectionServiceTests
  • StartConnectionAsync_ShouldRetryOnException_ExceptVersionNotAllowed (~6.0s)
  1. ByteSync.Client.UnitTests.ViewModels.TrustedNetworks.AddTrustedClientViewModelTests
  • Class total: ~9.1s across 6 tests
  • Individual tests around ~3.0s
  1. ByteSync.Client.UnitTests.Services.Misc.Factories.PolicyFactoryTests
  • Class total: ~13.2s across 14 tests
  • Many tests around ~1.0s (likely retry/wait related)

Recommended Method to Identify Slow Tests

Use TRX output and parse per-test durations.

  1. Run non-integration projects with TRX logs:
New-Item -ItemType Directory -Force -Path .artifacts/test-trx | Out-Null

dotnet test tests\ByteSync.Common.Tests\ByteSync.Common.Tests.csproj --no-build --logger "trx;LogFileName=ByteSync.Common.Tests.trx" --results-directory .artifacts/test-trx

dotnet test tests\ByteSync.Functions.UnitTests\ByteSync.Functions.UnitTests.csproj --no-build --logger "trx;LogFileName=ByteSync.Functions.UnitTests.trx" --results-directory .artifacts/test-trx

dotnet test tests\ByteSync.ServerCommon.Tests\ByteSync.ServerCommon.Tests.csproj --no-build --logger "trx;LogFileName=ByteSync.ServerCommon.Tests.trx" --results-directory .artifacts/test-trx

dotnet test tests\ByteSync.Client.UnitTests\ByteSync.Client.UnitTests.csproj --no-build --logger "trx;LogFileName=ByteSync.Client.UnitTests.trx" --results-directory .artifacts/test-trx
  1. Parse TRX files to extract top slow tests and class totals (PowerShell script can be added in repo later if useful).

  2. Track and publish:

  • Top 20 slowest tests
  • Top 10 slowest test classes by cumulative duration
  • Total duration per test project

Optimization Guidance

  • Remove real waiting/sleeping from unit tests by using controllable clocks/schedulers.
  • For retry/policy tests, inject policies with reduced delay or fake timing providers.
  • For crypto tests, reduce payload sizes/iteration counts when the behavior under test does not require heavy workloads.
  • Avoid expensive setup duplication by using shared fixtures where appropriate.
  • Keep tests deterministic and CI-stable while reducing runtime.

Suggested Acceptance Criteria

  • Non-integration total runtime reduced significantly (target: at least 30% reduction from current baseline).
  • ByteSync.Client.UnitTests runtime reduced first (main contributor).
  • Slow-test detection method documented and reusable.
  • A follow-up baseline posted in this issue after improvements.

paul-fresquet avatar Apr 01 '26 06:04 paul-fresquet