@@ -18,12 +18,12 @@ import java.net.InetSocketAddress
18
18
import scala .collection .immutable .Seq
19
19
20
20
import org .apache .pekko
21
- import pekko .actor .Props
21
+ import pekko .actor .{ ActorKilledException , Kill , Props }
22
22
import pekko .io .Tcp
23
23
import pekko .io .Tcp .{ Connected , PeerClosed , Register }
24
24
import pekko .io .dns .{ RecordClass , RecordType }
25
25
import pekko .io .dns .internal .DnsClient .Answer
26
- import pekko .testkit .{ ImplicitSender , PekkoSpec , TestProbe }
26
+ import pekko .testkit .{ EventFilter , ImplicitSender , PekkoSpec , TestProbe }
27
27
28
28
class TcpDnsClientSpec extends PekkoSpec with ImplicitSender {
29
29
import TcpDnsClient ._
@@ -107,5 +107,24 @@ class TcpDnsClientSpec extends PekkoSpec with ImplicitSender {
107
107
answerProbe.expectMsg(Answer (42 , Nil ))
108
108
answerProbe.expectMsg(Answer (43 , Nil ))
109
109
}
110
+
111
+ " fail when the connection just terminates" in {
112
+ val tcpExtensionProbe = TestProbe ()
113
+ val answerProbe = TestProbe ()
114
+ val connectionProbe = TestProbe ()
115
+
116
+ val client = system.actorOf(Props (new TcpDnsClient (tcpExtensionProbe.ref, dnsServerAddress, answerProbe.ref)))
117
+
118
+ client ! exampleRequestMessage
119
+
120
+ tcpExtensionProbe.expectMsg(Tcp .Connect (dnsServerAddress))
121
+ connectionProbe.send(tcpExtensionProbe.lastSender, Connected (dnsServerAddress, localAddress))
122
+ connectionProbe.expectMsgType[Register ]
123
+
124
+ EventFilter [ActorKilledException ](occurrences = 1 ).intercept {
125
+ // simulate connection stopping due to register timeout => client must fail
126
+ connectionProbe.ref ! Kill
127
+ }
128
+ }
110
129
}
111
130
}
0 commit comments