Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in-process test cluster #9148

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

ReubenBond
Copy link
Member

@ReubenBond ReubenBond commented Sep 25, 2024

This PR adds an in-process test cluster, InProcessTestCluster. The advantages of this over the existing TestCluster are:

  • Silos & clients can be configured using simple delegates (rather than 'configurator' types). This makes it much easier to configure shared dependencies across silos & clients
  • Silos expose their IServiceProvider, so dependencies can be retrieved and called as part of your test (eg, for fault injection, state inspection)
  • The cluster uses a new in-memory clustering & directory provider, so tests which start & stop silos do not need to worry about stopping the 'Primary' silo.

Here's an example:

// Setup
var builder = new InProcessTestClusterBuilder(initialSilosCount: 4);
builder.ConfigureClient(c => c.AddMemoryStreams("foo"));
builder.ConfigureSilo((siloOptions, siloBuilder) => siloBuilder.AddMemoryStreams("foo"));
await using var cluster = builder.Build();
await cluster.DeployAsync();

// Act
var value = await cluster.Client.GetGrain<IEchoGrain>(Guid.NewGuid()).Echo("test");

// Assert
Assert.Equal("test", value);
Microsoft Reviewers: Open in CodeFlow

@ReubenBond ReubenBond merged commit 0256eb6 into dotnet:main Oct 1, 2024
22 checks passed
@ReubenBond ReubenBond deleted the feature/inprocesstestcluster branch October 1, 2024 14:17
@github-actions github-actions bot locked and limited conversation to collaborators Nov 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant