Skip to content

Commit

Permalink
create TestFixture to ensure pools are created only once and then pro…
Browse files Browse the repository at this point in the history
…perly disposed
  • Loading branch information
Aaronontheweb committed May 21, 2019
1 parent 5d2f46b commit 3cf0142
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
23 changes: 21 additions & 2 deletions src/core/Akka.Remote.TestKit.Tests/RemoteConnectionSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,26 @@

namespace Akka.Remote.TestKit.Tests
{
public class RemoteConnectionSpecs : AkkaSpec
public class RemoteConnectionFixture : IDisposable
{
private IEventLoopGroup _clientGroup;
private IEventLoopGroup _serverGroup;

public RemoteConnectionFixture()
{
// allocate connection pools in advance - will be reused on subsequent RemoteConnection.CreateConnection calls
_clientGroup = RemoteConnection.GetClientWorkerPool(1);
_serverGroup = RemoteConnection.GetServerPool(1);
}

public void Dispose()
{
// dispose all of the event loop groups created
RemoteConnection.ReleaseAll().Wait(TimeSpan.FromSeconds(3));
}
}

public class RemoteConnectionSpecs : AkkaSpec, IClassFixture<RemoteConnectionFixture>
{
private const string Config = @"
akka.testconductor.barrier-timeout = 5s
Expand All @@ -33,7 +52,7 @@ public class RemoteConnectionSpecs : AkkaSpec
akka.actor.debug.lifecycle = on
";

public RemoteConnectionSpecs(ITestOutputHelper output) : base(Config, output)
public RemoteConnectionSpecs(RemoteConnectionFixture fixture, ITestOutputHelper output) : base(Config, output)
{

}
Expand Down
4 changes: 2 additions & 2 deletions src/core/Akka.Remote.TestKit/RemoteConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private static void ApplyChannelPipeline(IChannel channel, IChannelHandler handl
#region Static methods

private static IEventLoopGroup _clientPool;
private static IEventLoopGroup GetClientWorkerPool(int poolSize)
internal static IEventLoopGroup GetClientWorkerPool(int poolSize)
{
if (_clientPool == null)
{
Expand All @@ -73,7 +73,7 @@ private static IEventLoopGroup GetClientWorkerPool(int poolSize)
}

private static IEventLoopGroup _serverPool;
private static IEventLoopGroup GetServerPool(int poolSize)
internal static IEventLoopGroup GetServerPool(int poolSize)
{
if (_serverPool == null)
{
Expand Down

0 comments on commit 3cf0142

Please sign in to comment.