Skip to content

Commit

Permalink
Reduce the tomfoolery in EchoTaskGrainTests
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenBond committed Oct 20, 2023
1 parent 2d3f369 commit 759c1e9
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions test/DefaultCluster.Tests/EchoTaskGrainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class EchoTaskGrainTests : HostedTestClusterEnsureDefaultStarted
private readonly TimeSpan timeout = Debugger.IsAttached ? TimeSpan.FromMinutes(10) : TimeSpan.FromSeconds(10);
private const string expectedEcho = "Hello from EchoGrain";
private const string expectedEchoError = "Error from EchoGrain";
private IEchoTaskGrain grain;

public static readonly TimeSpan Epsilon = TimeSpan.FromSeconds(1);

Expand All @@ -30,7 +29,7 @@ public EchoTaskGrainTests(DefaultClusterFixture fixture)
[Fact, TestCategory("BVT"), TestCategory("Echo")]
public void EchoGrain_GetGrain()
{
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
_ = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
}

[Fact, TestCategory("BVT"), TestCategory("Echo")]
Expand All @@ -39,7 +38,7 @@ public async Task EchoGrain_Echo()
Stopwatch clock = new Stopwatch();

clock.Start();
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
this.Logger.LogInformation("CreateGrain took {Elapsed}", clock.Elapsed);

clock.Restart();
Expand All @@ -52,7 +51,7 @@ public async Task EchoGrain_Echo()
[Fact, TestCategory("BVT"), TestCategory("Echo")]
public async Task EchoGrain_EchoError()
{
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());

Task<string> promise = grain.EchoErrorAsync(expectedEchoError);
await promise.ContinueWith(t =>
Expand All @@ -69,7 +68,7 @@ await promise.ContinueWith(t =>
[Fact, TestCategory("SlowBVT"), TestCategory("Echo"), TestCategory("Timeout")]
public async Task EchoGrain_Timeout_ContinueWith()
{
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());

TimeSpan delay5 = TimeSpan.FromSeconds(30); // grain call timeout (set in config)
TimeSpan delay45 = TimeSpan.FromSeconds(45);
Expand All @@ -94,7 +93,7 @@ await promise.ContinueWith(
[Fact, TestCategory("SlowBVT"), TestCategory("Echo")]
public async Task EchoGrain_Timeout_Await()
{
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());

TimeSpan delay5 = TimeSpan.FromSeconds(5);
TimeSpan delay25 = TimeSpan.FromSeconds(25);
Expand All @@ -118,7 +117,7 @@ public async Task EchoGrain_Timeout_Await()
[Fact, TestCategory("SlowBVT"), TestCategory("Echo"), TestCategory("Timeout")]
public void EchoGrain_Timeout_Result()
{
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());

TimeSpan delay5 = TimeSpan.FromSeconds(5);
TimeSpan delay25 = TimeSpan.FromSeconds(25);
Expand All @@ -145,15 +144,33 @@ public async Task EchoGrain_LastEcho()
{
Stopwatch clock = new Stopwatch();

await EchoGrain_Echo();
clock.Start();
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
this.Logger.LogInformation("CreateGrain took {Elapsed}", clock.Elapsed);

clock.Restart();
string received = await grain.EchoAsync(expectedEcho);
this.Logger.LogInformation("EchoGrain.Echo took {Elapsed}", clock.Elapsed);

Assert.Equal(expectedEcho, received);

clock.Start();
string received = await grain.GetLastEchoAsync();

received = await grain.GetLastEchoAsync();
this.Logger.LogInformation("EchoGrain.LastEcho took {Elapsed}", clock.Elapsed);

Assert.Equal(expectedEcho, received); // LastEcho-Echo

await EchoGrain_EchoError();
Task<string> promise = grain.EchoErrorAsync(expectedEchoError);
await promise.ContinueWith(t =>
{
if (!t.IsFaulted) Assert.True(false); // EchoError should not have completed successfully

Exception exc = t.Exception;
while (exc is AggregateException) exc = exc.InnerException;
string received = exc.Message;
Assert.Equal(expectedEchoError, received);
}).WithTimeout(timeout);

clock.Restart();
received = await grain.GetLastEchoAsync();
Expand All @@ -169,7 +186,7 @@ public async Task EchoGrain_Ping()

string what = "CreateGrain";
clock.Start();
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
this.Logger.LogInformation("{What} took {Elapsed}", what, clock.Elapsed);

what = "EchoGrain.Ping";
Expand All @@ -186,7 +203,7 @@ public async Task EchoGrain_PingSilo_Local()

string what = "CreateGrain";
clock.Start();
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
this.Logger.LogInformation("{What} took {Elapsed}", what, clock.Elapsed);

what = "EchoGrain.PingLocalSilo";
Expand All @@ -202,7 +219,7 @@ public async Task EchoGrain_PingSilo_Remote()

string what = "CreateGrain";
clock.Start();
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
this.Logger.LogInformation("{What} took {Elapsed}", what, clock.Elapsed);

SiloAddress silo1 = HostedCluster.Primary.SiloAddress;
Expand All @@ -226,7 +243,7 @@ public async Task EchoGrain_PingSilo_OtherSilo()

string what = "CreateGrain";
clock.Start();
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
this.Logger.LogInformation("{What} took {Elapsed}", what, clock.Elapsed);

what = "EchoGrain.PingOtherSilo";
Expand All @@ -242,7 +259,7 @@ public async Task EchoGrain_PingSilo_OtherSilo_Membership()

string what = "CreateGrain";
clock.Start();
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
this.Logger.LogInformation("{What} took {Elapsed}", what, clock.Elapsed);

what = "EchoGrain.PingOtherSiloMembership";
Expand Down

0 comments on commit 759c1e9

Please sign in to comment.