Skip to content

Commit

Permalink
Remove IAsyncLifetime from TestKit (#6475)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkatufus committed Mar 1, 2023
1 parent 6a535f3 commit 1cfa04e
Show file tree
Hide file tree
Showing 52 changed files with 217 additions and 285 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ public CoordinatedShutdownShardingSpec(ITestOutputHelper helper) : base(SpecConf
});
}

protected override async Task AfterAllAsync()
protected override void AfterAll()
{
await base.AfterAllAsync();
await ShutdownAsync(_sys1);
await ShutdownAsync(_sys2);
base.AfterAll();
Shutdown(_sys1);
Shutdown(_sys2);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public ShardRegionQueriesHashCodeSpecs(ITestOutputHelper outputHelper) : base(Ge
AwaitAssert(() => { proxyCluster.SelfMember.Status.ShouldBe(MemberStatus.Up); });
}

protected override async Task AfterAllAsync()
protected override void AfterAll()
{
await ShutdownAsync(_proxySys);
await base.AfterAllAsync();
Shutdown(_proxySys);
base.AfterAll();
}

private static Config GetConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public ShardRegionQueriesSpecs(ITestOutputHelper outputHelper) : base(GetConfig(
AwaitAssert(() => { proxyCluster.SelfMember.Status.ShouldBe(MemberStatus.Up); });
}

protected override async Task AfterAllAsync()
protected override void AfterAll()
{
await ShutdownAsync(_proxySys);
await base.AfterAllAsync();
Shutdown(_proxySys);
base.AfterAll();
}

private Option<(string, object)> ExtractEntityId(object message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ public ShardRegionSpec(ITestOutputHelper helper) : base(SpecConfig, helper)
region2 = StartShard(sysB);
}

protected override async Task AfterAllAsync()
protected override void AfterAll()
{
if(sysA != null)
await ShutdownAsync(sysA);
Shutdown(sysA);
if(sysB != null)
await ShutdownAsync(sysB);
await base.AfterAllAsync();
Shutdown(sysB);
base.AfterAll();
}

private IActorRef StartShard(ActorSystem sys)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ public void A_cluster_singleton_must_be_accessible_from_two_nodes_in_a_cluster()
}, TimeSpan.FromSeconds(3));
}

protected override async Task AfterAllAsync()
protected override void AfterAll()
{
await base.AfterAllAsync();
await _system2.Terminate().AwaitWithTimeout(TimeSpan.FromSeconds(3));
base.AfterAll();
Shutdown(_system2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ private async Task ClusterSingleton_that_is_leaving_must_quickly_hand_over_to_ne
}
}

protected override async Task AfterAllAsync()
protected override void AfterAll()
{
await base.AfterAllAsync();
base.AfterAll();
foreach (var s in _systems)
await ShutdownAsync(s);
Shutdown(s);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ public void Restarting_cluster_node_during_hand_over_must_restart_singletons_in_
});
}

protected override async Task AfterAllAsync()
protected override void AfterAll()
{
await base.AfterAllAsync();
await ShutdownAsync(_sys1);
await ShutdownAsync(_sys2);
await ShutdownAsync(_sys3);
base.AfterAll();
Shutdown(_sys1);
Shutdown(_sys2);
Shutdown(_sys3);
if (_sys4 != null)
await ShutdownAsync(_sys4);
Shutdown(_sys4);
}

public class Singleton : ReceiveActor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ public void Singleton_should_consider_AppVersion_when_handing_over()
});
}

protected override async Task AfterAllAsync()
protected override void AfterAll()
{
await base.AfterAllAsync();
await ShutdownAsync(_sys2);
await ShutdownAsync(_sys3);
base.AfterAll();
Shutdown(_sys2);
Shutdown(_sys3);
}

public class Singleton : ReceiveActor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ public void Restarting_cluster_node_with_same_hostname_and_port_must_handover_to
});
}

protected override async Task AfterAllAsync()
protected override void AfterAll()
{
await base.AfterAllAsync();
await ShutdownAsync(_sys1);
await ShutdownAsync(_sys2);
base.AfterAll();
Shutdown(_sys1);
Shutdown(_sys2);
if(_sys3 != null)
await ShutdownAsync(_sys3);
Shutdown(_sys3);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,12 +646,12 @@ public async Task ORMultiValueDictionary_WithValueDeltas_LargeDataSet()
node3EntriesBCA["A"].Should().BeEquivalentTo(entryA1);
}

protected override async Task AfterAllAsync()
protected override void AfterAll()
{
await base.AfterAllAsync();
await ShutdownAsync(_sys1);
await ShutdownAsync(_sys2);
await ShutdownAsync(_sys3);
base.AfterAll();
Shutdown(_sys1);
Shutdown(_sys2);
Shutdown(_sys3);
GC.Collect();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,22 @@ internal class NotInServices
}


public override async Task InitializeAsync()
public async Task InitializeAsync()
{
await _akkaService.StartAsync(default);
InitializeLogger(_akkaService.ActorSystem);
await base.InitializeAsync();
}

public override async Task DisposeAsync()
protected override void AfterAll()
{
var sys = _serviceProvider.GetRequiredService<AkkaService>().ActorSystem;
await sys.Terminate();
await base.DisposeAsync();
Shutdown(sys);
base.AfterAll();
}

public Task DisposeAsync()
{
return Task.CompletedTask;
}

internal class AkkaService : IHostedService
Expand Down
51 changes: 18 additions & 33 deletions src/contrib/testkits/Akka.TestKit.Xunit2/TestKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Akka.TestKit.Xunit2
/// This class represents an Akka.NET TestKit that uses <a href="https://xunit.github.io/">xUnit</a>
/// as its testing framework.
/// </summary>
public class TestKit : TestKitBase, IAsyncLifetime, IDisposable
public class TestKit : TestKitBase, IDisposable
{
private class PrefixedOutput : ITestOutputHelper
{
Expand Down Expand Up @@ -50,6 +50,9 @@ public void WriteLine(string format, params object[] args)
/// </summary>
protected readonly ITestOutputHelper Output;

private bool _disposed;
private bool _disposing;

/// <summary>
/// <para>
/// Initializes a new instance of the <see cref="TestKit"/> class.
Expand Down Expand Up @@ -122,26 +125,9 @@ public TestKit(string config, ITestOutputHelper output = null)
/// </summary>
protected static XunitAssertions Assertions { get; } = new XunitAssertions();

/// <summary>
/// This method is called when a test ends.
///
/// <remarks>
/// If you override this, then make sure you either call base.AfterAllAsync()
/// to shut down the system. Otherwise a memory leak will occur.
/// </remarks>
/// </summary>
protected virtual async Task AfterAllAsync()
{
#pragma warning disable CS0618
AfterAll();
#pragma warning restore CS0618
await ShutdownAsync();
}

/// <summary>
/// This method is called when a test ends.
/// </summary>
[Obsolete("AfterAll() is deprecated, please use AfterAllAsync() instead")]
protected virtual void AfterAll()
{
}
Expand Down Expand Up @@ -172,18 +158,6 @@ protected void InitializeLogger(ActorSystem system, string prefix)
.ConfigureAwait(false).GetAwaiter().GetResult();
}
}
public virtual Task InitializeAsync()
{
return Task.CompletedTask;
}

public virtual async Task DisposeAsync()
{
await AfterAllAsync();
#pragma warning disable CS0618
Dispose();
#pragma warning restore CS0618
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Expand All @@ -194,12 +168,23 @@ public virtual async Task DisposeAsync()
/// has been called by the runtime from inside the finalizer and only unmanaged resources can
/// be disposed.
/// </param>
[Obsolete("Dispose(bool) is deprecated, please use DisposeAsync() instead")]
protected virtual void Dispose(bool disposing)
public virtual void Dispose(bool disposing)
{
if (_disposing || _disposed)
return;

_disposing = true;
try
{
AfterAll();
}
finally
{
Shutdown();
_disposed = true;
}
}

[Obsolete("Dispose() is obsolete, please use DisposeAsync() instead")]
public void Dispose()
{
Dispose(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public ActorRefIgnoreSerializationSpec(ITestOutputHelper output)
system2 = ActorSystem.Create("sys2", Config);
}

protected override async Task AfterAllAsync()
protected override void AfterAll()
{
await base.AfterAllAsync();
await ShutdownAsync(system1);
await ShutdownAsync(system2);
base.AfterAll();
Shutdown(system1);
Shutdown(system2);
}

[Fact]
Expand Down
14 changes: 7 additions & 7 deletions src/core/Akka.Cluster.Tests/ClusterSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public async Task A_cluster_must_be_allowed_to_join_and_leave_with_local_address
}
finally
{
await ShutdownAsync(sys2);
Shutdown(sys2);
}
}

Expand Down Expand Up @@ -375,7 +375,7 @@ public async Task A_cluster_JoinAsync_must_fail_if_could_not_connect_to_cluster(
}
finally
{
await ShutdownAsync(sys);
Shutdown(sys);
}
}

Expand Down Expand Up @@ -436,7 +436,7 @@ public async Task A_cluster_JoinSeedNodesAsync_must_fail_if_could_not_connect_to
}
finally
{
await ShutdownAsync(sys);
Shutdown(sys);
}
}

Expand Down Expand Up @@ -482,7 +482,7 @@ public async Task A_cluster_must_leave_via_CoordinatedShutdownRun()
}
finally
{
await ShutdownAsync(sys2);
Shutdown(sys2);
}
}

Expand Down Expand Up @@ -519,7 +519,7 @@ public async Task A_cluster_must_leave_via_CoordinatedShutdownRun_when_member_st
}
finally
{
await ShutdownAsync(sys2);
Shutdown(sys2);
}
}

Expand Down Expand Up @@ -553,7 +553,7 @@ public async Task A_cluster_must_terminate_ActorSystem_via_leave_CoordinatedShut
}
finally
{
await ShutdownAsync(sys2);
Shutdown(sys2);
}
}

Expand Down Expand Up @@ -586,7 +586,7 @@ public async Task A_cluster_must_terminate_ActorSystem_via_Down_CoordinatedShutd
}
finally
{
await ShutdownAsync(sys3);
Shutdown(sys3);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/core/Akka.Cluster.Tests/ShutdownAfterJoinSeedNodesSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public ShutdownAfterJoinSeedNodesSpec() : base(Config)
_ordinary1 = ActorSystem.Create(Sys.Name, Sys.Settings.Config);
}

protected override async Task AfterAllAsync()
protected override void AfterAll()
{
await base.AfterAllAsync();
await ShutdownAsync(_seed1);
await ShutdownAsync(_seed2);
await ShutdownAsync(_ordinary1);
Shutdown(_seed1);
Shutdown(_seed2);
Shutdown(_ordinary1);
base.AfterAll();
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions src/core/Akka.Persistence.TCK.Tests/LocalSnapshotStoreSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public LocalSnapshotStoreSpec(ITestOutputHelper output)

protected override bool SupportsSerialization => true;

protected override void Dispose(bool disposing)
protected override void AfterAll()
{
base.Dispose(disposing);
Sys.DeleteStorageLocations(_path);
base.AfterAll();
}

[Fact]
Expand Down

0 comments on commit 1cfa04e

Please sign in to comment.