-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHelloActorTest.cs
More file actions
61 lines (51 loc) · 2.07 KB
/
HelloActorTest.cs
File metadata and controls
61 lines (51 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using Akka.Actor;
using Akka.TestKit;
using AkkaDotModule.ActorSample;
using AkkaNetCoreTest;
using Xunit;
using Xunit.Abstractions;
// http://wiki.webnori.com/display/webfr/UnitTest+For+Actor+Message
namespace TestAkkaDotModule.TestActors
{
public class HelloActorTest : TestKitXunit
{
protected TestProbe probe;
public HelloActorTest(ITestOutputHelper output) : base(output)
{
Setup();
}
public void Setup()
{
//테스트 관찰자..
probe = this.CreateTestProbe();
}
/// <summary>
/// 사용목적 : 특정 메시지를 송신하고, 완료처리를 비동기로 받을때 사용
/// </summary>
/// <param name="timeSec"></param>
/// <param name="elemntPerSec"></param>
[Theory(DisplayName = "hello를 전송하면 world를 비동기적으로 수신")]
[InlineData(3)]
public void TestFireAndForget(int expectedTestSec)
{
var helloActor = Sys.ActorOf(Props.Create(() => new HelloActor("Minsu")));
// 응답 받을 액터를 지정한다. (첫번째:지정자 , 두번째:전송자)
helloActor.Tell(probe.Ref, this.TestActor);
// 두번째 인자의 Sender(전송장)가 받는 결과값 검사
ExpectMsg("done", TimeSpan.FromSeconds(1));
Within(TimeSpan.FromSeconds(expectedTestSec), () =>
{
helloActor.Tell("hello", this.TestActor);
// 지정자가 받는 메시지 검사
probe.ExpectMsg("world", TimeSpan.FromSeconds(1));
// 송신을 하지만 응답을 꼭 알필요없이 Next수행 - fire and foget(군사용어)
helloActor.Tell("fire", this.TestActor);
helloActor.Tell("fire", this.TestActor);
helloActor.Tell("fire", this.TestActor);
// 응답메시지가 없음을 검사
probe.ExpectNoMsg(TimeSpan.FromSeconds(1));
});
}
}
}