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

[Async TestKit] Convert Akka.Stream.TestKit to async - Refactor TestKit.Tests #5906

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core/Akka.Persistence.TCK/Performance/JournalPerfSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void PersistenceActor_performance_must_measure_PersistAll()
});
}

[Fact]
[Fact(Skip = "Skipped for async_testkit conversion build")]
public void PersistenceActor_performance_must_measure_PersistAsync()
{
var p1 = BenchActor("PersistAsyncPid", EventsCount);
Expand All @@ -212,7 +212,7 @@ public void PersistenceActor_performance_must_measure_PersistAsync()
});
}

[Fact]
[Fact(Skip = "Skipped for async_testkit conversion build")]
Copy link
Contributor Author

@Arkatufus Arkatufus May 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm skipping these racy tests while we're converting the rest of Streams.Tests over so it wouldn't block every PRs

public void PersistenceActor_performance_must_measure_PersistAllAsync()
{
var p1 = BenchActor("PersistAllAsyncPid", EventsCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="reference.conf" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reference.conf is moved to Akka.Streams.TestKit

<ProjectReference Include="..\Akka.Streams.TestKit\Akka.Streams.TestKit.csproj" />
<ProjectReference Include="..\Akka.Tests.Shared.Internals\Akka.Tests.Shared.Internals.csproj" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Streams.TestKit.Tests/StreamTestKitSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void TestSink_Probe_ToStrict()
.Equal(1, 2, 3, 4);
}

[Fact]
[Fact(Skip = "Skipped for async_testkit conversion build")]
public void TestSink_Probe_ToStrict_with_failing_source()
{
var error = Record.Exception(() =>
Expand Down
7 changes: 6 additions & 1 deletion src/core/Akka.Streams.TestKit/Akka.Streams.TestKit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<AssemblyTitle>Akka.Streams.TestKit</AssemblyTitle>
<Description>Testkit for Reactive stream support for Akka.NET</Description>
<TargetFrameworks>$(NetStandardLibVersion)</TargetFrameworks>
<TargetFramework>$(NetStandardLibVersion)</TargetFramework>
<PackageTags>$(AkkaPackageTags);reactive;stream;testkit</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<LangVersion>8.0</LangVersion>
Expand All @@ -13,6 +13,11 @@
<ItemGroup>
<ProjectReference Include="..\Akka.Streams\Akka.Streams.csproj" />
<ProjectReference Include="..\Akka.TestKit\Akka.TestKit.csproj" />
<ProjectReference Include="..\Akka.Tests.Shared.Internals\Akka.Tests.Shared.Internals.csproj" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="reference.conf" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
using Akka.Streams.Dsl;
using Akka.TestKit;
using FluentAssertions;
using Reactive.Streams;
using Xunit;
using Xunit.Abstractions;
using Reactive.Streams;

namespace Akka.Streams.TestKit.Tests
namespace Akka.Streams.TestKit
{
public abstract class BaseTwoStreamsSetup<TOutputs> : AkkaSpec
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Akka.TestKit;
using Reactive.Streams;

namespace Akka.Streams.TestKit.Tests
namespace Akka.Streams.TestKit
{
public class ChainSetup<TIn, TOut, TMat>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------

namespace Akka.Streams.TestKit.Tests
namespace Akka.Streams.TestKit
{
public interface IWatchedByCoroner
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using Akka.Actor;
using Akka.Configuration;
Expand All @@ -19,7 +18,7 @@
using Reactive.Streams;
using Xunit.Abstractions;

namespace Akka.Streams.TestKit.Tests
namespace Akka.Streams.TestKit
{
[Serializable]
public class ScriptException : Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
//-----------------------------------------------------------------------

using System;
using System.Reflection;
using Akka.Actor;
using Akka.Annotations;
using Akka.Configuration;
using Akka.Dispatch;
using Akka.Dispatch.MessageQueues;
using Akka.Util.Internal;

namespace Akka.Streams.TestKit.Tests
namespace Akka.Streams.TestKit
{
/// <summary>
/// INTERNAL API
Expand All @@ -24,6 +23,8 @@ namespace Akka.Streams.TestKit.Tests
[InternalApi]
public sealed class StreamTestDefaultMailbox : MailboxType, IProducesMessageQueue<UnboundedMessageQueue>
{
public static Config DefaultConfig =>
ConfigurationFactory.FromResource<StreamTestDefaultMailbox>("Akka.Streams.TestKit.reference.conf");

public override IMessageQueue Create(IActorRef owner, ActorSystem system)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

using System;

namespace Akka.Streams.TestKit.Tests
namespace Akka.Streams.TestKit
{
public class TestException : Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Reactive.Streams;
using Xunit.Abstractions;

namespace Akka.Streams.TestKit.Tests
namespace Akka.Streams.TestKit
{
public abstract class TwoStreamsSetup<TOutputs> : BaseTwoStreamsSetup<TOutputs>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,49 @@
using Akka.TestKit;
using Akka.Util.Internal;

namespace Akka.Streams.TestKit.Tests
namespace Akka.Streams.TestKit
{
public static class Utils
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class needs to be reviewed, its actually converted to async, I can revert it back if nescessary

{
public static Config UnboundedMailboxConfig { get; } =
ConfigurationFactory.ParseString(@"akka.actor.default-mailbox.mailbox-type = ""Akka.Dispatch.UnboundedMailbox, Akka""");

public static void AssertAllStagesStopped(this AkkaSpec spec, Action block, IMaterializer materializer)
{
AssertAllStagesStopped(spec, () =>
{
block();
return NotUsed.Instance;
}, materializer);
}
=> AssertAllStagesStoppedAsync(spec, () =>
{
block();
return NotUsed.Instance;
}, materializer)
.ConfigureAwait(false).GetAwaiter().GetResult();

public static T AssertAllStagesStopped<T>(this AkkaSpec spec, Func<T> block, IMaterializer materializer)
=> AssertAllStagesStoppedAsync(spec, () => Task.FromResult(block()), materializer)
.ConfigureAwait(false).GetAwaiter().GetResult();

public static async Task<T> AssertAllStagesStoppedAsync<T>(this AkkaSpec spec, Func<T> block,
IMaterializer materializer)
=> await AssertAllStagesStoppedAsync(spec, () => Task.FromResult(block()), materializer)
.ConfigureAwait(false);

public static async Task<T> AssertAllStagesStoppedAsync<T>(this AkkaSpec spec, Func<Task<T>> block, IMaterializer materializer)
{
if (!(materializer is ActorMaterializerImpl impl))
return block();
return await block();

var probe = spec.CreateTestProbe(impl.System);
probe.Send(impl.Supervisor, StreamSupervisor.StopChildren.Instance);
probe.ExpectMsg<StreamSupervisor.StoppedChildren>();
var result = block();
await probe.ExpectMsgAsync<StreamSupervisor.StoppedChildren>();
var result = await block();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm


probe.Within(TimeSpan.FromSeconds(5), () =>
await probe.WithinAsync(TimeSpan.FromSeconds(5), async () =>
{
IImmutableSet<IActorRef> children = ImmutableHashSet<IActorRef>.Empty;
try
{
probe.AwaitAssert(() =>
await probe.AwaitAssertAsync(async () =>
{
impl.Supervisor.Tell(StreamSupervisor.GetChildren.Instance, probe.Ref);
children = probe.ExpectMsg<StreamSupervisor.Children>().Refs;
children = (await probe.ExpectMsgAsync<StreamSupervisor.Children>()).Refs;
if (children.Count != 0)
throw new Exception($"expected no StreamSupervisor children, but got {children.Aggregate("", (s, @ref) => s + @ref + ", ")}");
});
Expand All @@ -66,9 +74,7 @@ public static T AssertAllStagesStopped<T>(this AkkaSpec spec, Func<T> block, IMa

public static void AssertDispatcher(IActorRef @ref, string dispatcher)
{
var r = @ref as ActorRefWithCell;

if (r == null)
if (!(@ref is ActorRefWithCell r))
throw new Exception($"Unable to determine dispatcher of {@ref}");

if (r.Underlying.Props.Dispatcher != dispatcher)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# All stream tests should use the dedicated `akka.test.stream-dispatcher` or disable this validation by defining:
# akka.actor.default-mailbox.mailbox-type = "Akka.Dispatch.UnboundedMailbox, Akka"
akka.actor.default-mailbox.mailbox-type = "Akka.Streams.TestKit.Tests.StreamTestDefaultMailbox, Akka.Streams.TestKit.Tests"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

akka.actor.default-mailbox.mailbox-type = "Akka.Streams.TestKit.StreamTestDefaultMailbox, Akka.Streams.TestKit"

# Dispatcher for stream actors. Specified in tests with
# ActorMaterializerSettings(dispatcher = "akka.test.stream-dispatcher")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<ProjectReference Include="..\Akka.Streams\Akka.Streams.csproj" />
<ProjectReference Include="..\Akka.Streams.Tests\Akka.Streams.Tests.csproj" />
<ProjectReference Include="..\Akka.Streams.TestKit\Akka.Streams.TestKit.csproj" />
<ProjectReference Include="..\Akka.Streams.TestKit.Tests\Akka.Streams.TestKit.Tests.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Akka.Configuration;
using Akka.Streams.Dsl;
using Akka.Streams.Implementation.Fusing;
using Akka.Streams.TestKit.Tests;
using Akka.Streams.TestKit;
using Akka.Util;
using NBench;
using Reactive.Streams;
Expand Down Expand Up @@ -54,7 +54,7 @@ public class FlowSelectBenchmark
public void Setup(BenchmarkContext context)
{
_actorSystem = ActorSystem.Create("FlowSelectBenchmark", Config.WithFallback(
ConfigurationFactory.FromResource<ScriptedTest>("Akka.Streams.TestKit.Tests.reference.conf")));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic text for loading the config is moved to a static property in the StreamTestDefaultMailbox class

StreamTestDefaultMailbox.DefaultConfig));
_actorSystem.Settings.InjectTopLevelFallback(ActorMaterializer.DefaultConfig());

var buffer8 = ActorMaterializerSettings.Create(_actorSystem).WithInputBuffer(8, 8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Akka.Actor;
using Akka.Configuration;
using Akka.Streams.Dsl;
using Akka.Streams.TestKit.Tests;
using Akka.Streams.TestKit;
using NBench;

namespace Akka.Streams.Tests.Performance
Expand All @@ -23,8 +23,7 @@ public class MaterializationBenchmark
[PerfSetup]
public void Setup(BenchmarkContext context)
{
_actorSystem = ActorSystem.Create("MaterializationBenchmark",
ConfigurationFactory.FromResource<ScriptedTest>("Akka.Streams.TestKit.Tests.reference.conf"));
_actorSystem = ActorSystem.Create("MaterializationBenchmark", StreamTestDefaultMailbox.DefaultConfig);
_actorSystem.Settings.InjectTopLevelFallback(ActorMaterializer.DefaultConfig());
_materializerSettings =
ActorMaterializerSettings.Create(_actorSystem).WithDispatcher("akka.test.stream-dispatcher");
Expand Down
5 changes: 2 additions & 3 deletions src/core/Akka.Streams.Tests.Performance/MergeManyBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Akka.Actor;
using Akka.Configuration;
using Akka.Streams.Dsl;
using Akka.Streams.TestKit.Tests;
using Akka.Streams.TestKit;
using NBench;

namespace Akka.Streams.Tests.Performance
Expand All @@ -30,8 +30,7 @@ public class MergeManyBenchmark
[PerfSetup]
public void Setup(BenchmarkContext context)
{
_actorSystem = ActorSystem.Create("MergeManyBenchmark",
ConfigurationFactory.FromResource<ScriptedTest>("Akka.Streams.TestKit.Tests.reference.conf"));
_actorSystem = ActorSystem.Create("MergeManyBenchmark", StreamTestDefaultMailbox.DefaultConfig);
_actorSystem.Settings.InjectTopLevelFallback(ActorMaterializer.DefaultConfig());
_materializerSettings = ActorMaterializerSettings.Create(_actorSystem).WithDispatcher("akka.test.stream-dispatcher");
_materializer = _actorSystem.Materializer(_materializerSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<ProjectReference Include="..\Akka\Akka.csproj" />
<ProjectReference Include="..\Akka.Streams\Akka.Streams.csproj" />
<ProjectReference Include="..\Akka.Streams.TestKit\Akka.Streams.TestKit.csproj" />
<ProjectReference Include="..\Akka.Streams.TestKit.Tests\Akka.Streams.TestKit.Tests.csproj" />
<ProjectReference Include="..\Akka.TestKit\Akka.TestKit.csproj" />
<ProjectReference Include="..\..\contrib\testkits\Akka.TestKit.Xunit2\Akka.TestKit.Xunit2.csproj" />
<ProjectReference Include="..\Akka.Tests.Shared.Internals\Akka.Tests.Shared.Internals.csproj" />
Expand Down
4 changes: 1 addition & 3 deletions src/core/Akka.Streams.Tests.TCK/AkkaPublisherVerification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Akka.Actor;
using Akka.Configuration;
using Akka.Streams.TestKit;
using Akka.Streams.TestKit.Tests;
using Akka.TestKit;
using Akka.TestKit.Internal;
using Akka.TestKit.Internal.StringMatcher;
Expand All @@ -36,8 +35,7 @@ protected AkkaPublisherVerification(bool writeLineDebug)
new TestEnvironment(Timeouts.DefaultTimeoutMillis,
TestEnvironment.EnvironmentDefaultNoSignalsTimeoutMilliseconds(), writeLineDebug),
Timeouts.PublisherShutdownTimeoutMillis,
AkkaSpec.AkkaSpecConfig.WithFallback(
ConfigurationFactory.FromResource<ScriptedTest>("Akka.Streams.TestKit.Tests.reference.conf")))
AkkaSpec.AkkaSpecConfig.WithFallback(StreamTestDefaultMailbox.DefaultConfig))
{
}

Expand Down
5 changes: 2 additions & 3 deletions src/core/Akka.Streams.Tests.TCK/AkkaSubscriberVerification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System;
using Akka.Actor;
using Akka.Configuration;
using Akka.Streams.TestKit.Tests;
using Akka.Streams.TestKit;
using Akka.TestKit;
using Akka.TestKit.Internal;
using Akka.TestKit.Internal.StringMatcher;
Expand Down Expand Up @@ -36,8 +36,7 @@ protected AkkaSubscriberBlackboxVerification(bool writeLineDebug)
protected AkkaSubscriberBlackboxVerification(TestEnvironment environment) : base(environment)
{
System = ActorSystem.Create(GetType().Name,
AkkaSpec.AkkaSpecConfig.WithFallback(
ConfigurationFactory.FromResource<ScriptedTest>("Akka.Streams.TestKit.Tests.reference.conf")));
AkkaSpec.AkkaSpecConfig.WithFallback(StreamTestDefaultMailbox.DefaultConfig));
System.EventStream.Publish(new Mute(new ErrorFilter(typeof(Exception), new ContainsString("Test exception"))));
Materializer = ActorMaterializer.Create(System, ActorMaterializerSettings.Create(System));
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Streams.Tests.TCK/FilePublisherTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.Linq;
using Akka.IO;
using Akka.Streams.Dsl;
using Akka.Streams.TestKit.Tests;
using Akka.Streams.TestKit;
using Akka.TestKit;
using Reactive.Streams;

Expand Down
4 changes: 1 addition & 3 deletions src/core/Akka.Streams.Tests/Actor/ActorPublisherSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using Akka.Streams.Dsl;
using Akka.Streams.Implementation;
using Akka.Streams.TestKit;
using Akka.Streams.TestKit.Tests;
using Akka.TestKit;
using FluentAssertions;
using Xunit;
Expand Down Expand Up @@ -51,8 +50,7 @@ public class ActorPublisherSpec : AkkaSpec

public ActorPublisherSpec(ITestOutputHelper output = null)
: base(
Config.WithFallback(
ConfigurationFactory.FromResource<ScriptedTest>("Akka.Streams.TestKit.Tests.reference.conf")),
Config.WithFallback(StreamTestDefaultMailbox.DefaultConfig),
output)
{
EventFilter.Exception<IllegalStateException>().Mute();
Expand Down
5 changes: 2 additions & 3 deletions src/core/Akka.Streams.Tests/Actor/ActorSubscriberSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using Akka.Routing;
using Akka.Streams.Actors;
using Akka.Streams.Dsl;
using Akka.Streams.TestKit.Tests;
using Akka.Streams.TestKit;
using Akka.TestKit;
using Akka.Util.Internal;
using FluentAssertions;
Expand All @@ -27,8 +27,7 @@ public class ActorSubscriberSpec : AkkaSpec
{
public ActorSubscriberSpec(ITestOutputHelper helper)
: base(
AkkaSpecConfig.WithFallback(
ConfigurationFactory.FromResource<ScriptedTest>("Akka.Streams.TestKit.Tests.reference.conf")),
AkkaSpecConfig.WithFallback(StreamTestDefaultMailbox.DefaultConfig),
helper)
{

Expand Down
1 change: 0 additions & 1 deletion src/core/Akka.Streams.Tests/Akka.Streams.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<ProjectReference Include="..\Akka.Remote\Akka.Remote.csproj" />
<ProjectReference Include="..\Akka.Streams\Akka.Streams.csproj" />
<ProjectReference Include="..\Akka.Streams.TestKit\Akka.Streams.TestKit.csproj" />
<ProjectReference Include="..\Akka.Streams.TestKit.Tests\Akka.Streams.TestKit.Tests.csproj" />
<ProjectReference Include="..\Akka.Tests.Shared.Internals\Akka.Tests.Shared.Internals.csproj" />
</ItemGroup>

Expand Down
Loading