Open sandboxFocus

Class TestSynchronizationProvider

Test implementation of Metalama.Framework.DesignTime.Rpc.ITestSynchronizationProvider that allows tests to control execution order by blocking at named synchronization points. This enables deterministic testing of concurrent code by letting tests wait for code to reach specific points and then release it.

Inheritance
TestSynchronizationProvider
Implements
ITestSynchronizationProvider
Namespace: Metalama.Testing.UnitTesting
Assembly: Metalama.Testing.UnitTesting.dll
Syntax
public sealed class TestSynchronizationProvider : ITestSynchronizationProvider, IDisposable
Remarks

Sync points are only active (blocking) when the test has registered interest by calling WaitForSyncPointReachedAsync(string, CancellationToken). Unregistered sync points are skipped without blocking.

Usage pattern:

  1. Register this provider with the service provider before starting the test.
  2. Start the operation being tested in a background task.
  3. Call WaitForSyncPointReachedAsync(string, CancellationToken) to wait until the code reaches the sync point.
  4. Perform any setup needed (e.g., register an extension) while code is blocked.
  5. Call ReleaseSyncPoint(string) to let the code continue.

Always call ReleaseAll() in test cleanup to avoid deadlocks if a test fails.

Constructors

Name Description
TestSynchronizationProvider(ITestOutputHelper?)

Methods

Name Description
Dispose()
EnableSyncPoint(string)

Called by test code. Enables a sync point so that code under test will block when reaching it. This must be called BEFORE starting the operation that will hit the sync point.

ReleaseAll()

Releases all sync points. Call this in test cleanup to avoid deadlocks if a test fails.

ReleaseSyncPoint(string)

Called by test code. Releases the code blocked at the named sync point.

WaitForSyncPointReachedAsync(string, CancellationToken)

Called by test code. Waits until the code under test reaches the named sync point. Also enables the sync point if not already enabled.

Extension Methods