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

added 2 tests - a true and a false positive #5529

Closed
wants to merge 1 commit into from
Closed
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
60 changes: 49 additions & 11 deletions src/core/Akka.Docs.Tests/Testkit/ProbeSampleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------

using System.Threading.Tasks;
using Akka.Actor;
using Akka.TestKit;
using Akka.TestKit.Xunit2;
Expand All @@ -14,7 +15,7 @@ namespace DocsExamples.Testkit
{
public class ProbeSampleTest : TestKit
{
#region ProbeSample_0
#region ProbeSample_0
public class Forwarder : ReceiveActor
{
private IActorRef target;
Expand All @@ -32,7 +33,7 @@ public void Test()
{
//create a test probe
var probe = CreateTestProbe();

//create a forwarder, injecting the probo's testActor
var props = Props.Create(() => new Forwarder(probe));
var forwarder = Sys.ActorOf(props, "forwarder");
Expand All @@ -42,9 +43,9 @@ public void Test()
probe.ExpectMsg(43);
Assert.Equal(TestActor, probe.LastSender);
}
#endregion ProbeSample_0
#endregion ProbeSample_0

#region MultipleProbeSample_0
#region MultipleProbeSample_0
[Fact]
public void MultipleProbes()
{
Expand All @@ -54,9 +55,9 @@ public void MultipleProbes()
Assert.StartsWith("worker", worker.Ref.Path.Name);
Assert.StartsWith("aggregator", aggregator.Ref.Path.Name);
}
#endregion MultipleProbeSample_0
#endregion MultipleProbeSample_0

#region ReplyingToProbeMessages_0
#region ReplyingToProbeMessages_0
[Fact]
public void ReplyingToProbeMessages()
{
Expand All @@ -68,9 +69,46 @@ public void ReplyingToProbeMessages()
ExpectMsg("world");
Assert.Equal(probe.Ref, LastSender);
}
#endregion ReplyingToProbeMessages_0

#region ForwardingProbeMessages_0
/// <summary>
/// this test is a true positive
/// </summary>
/// <returns></returns>
[Fact]
public async Task ReplyingToProbeMessagesAction()
{
await EventFilter.Error().ExpectAsync(0, action: () =>
{
var probe = CreateTestProbe();
probe.Tell("hello");
probe.ExpectMsg("hello");
probe.Reply("world");
ExpectMsg("world2");
Assert.Equal(probe.Ref, LastSender);
});
}

/// <summary>
/// this test is a false positive
/// </summary>
/// <returns></returns>
[Fact]
public async Task ReplyingToProbeMessagesFunc()
{
await EventFilter.Error().ExpectAsync(0, actionAsync: async () =>
{
var probe = CreateTestProbe();
probe.Tell("hello");
probe.ExpectMsg("hello");
probe.Reply("world");
await Task.Run(() => { ExpectMsg("world2"); });
Assert.Equal(probe.Ref, LastSender);
});
}

#endregion ReplyingToProbeMessages_0

#region ForwardingProbeMessages_0
[Fact]
public void ForwardingProbeMessages()
{
Expand All @@ -81,9 +119,9 @@ public void ForwardingProbeMessages()
ExpectMsg("hello");
Assert.Equal(TestActor, LastSender);
}
#endregion ForwardingProbeMessages_0
#endregion ForwardingProbeMessages_0

#region ProbeAutopilot_0
#region ProbeAutopilot_0
[Fact]
public void ProbeAutopilot()
{
Expand All @@ -101,7 +139,7 @@ public void ProbeAutopilot()
probe.Tell("world");
ExpectNoMsg();
}
#endregion ProbeAutopilot_0
#endregion ProbeAutopilot_0

}
}