spec/celluloid/io/tcp_server_spec.rb in celluloid-io-0.17.2 vs spec/celluloid/io/tcp_server_spec.rb in celluloid-io-0.17.3
- old
+ new
@@ -26,9 +26,36 @@
client.write payload
expect(peer.read(payload.size)).to eq payload
end
end
+ it "sends information to the client later" do
+ class LaterActor
+ include Celluloid::IO
+
+ def send_later(socket)
+ peer = socket.accept
+ after(0.4) { peer.write "1" }
+ after(0.4) { peer.write "2" }
+ peer
+ end
+ end
+ with_tcp_server(example_port) do |subject|
+ thread = Thread.new { TCPSocket.new(example_addr, example_port) }
+ actor = LaterActor.new
+ begin
+ peer = actor.send_later(subject)
+ client = thread.value
+ client.write payload
+ expect(peer.read(payload.size)).to eq payload # confirm the client read
+ Timeout::timeout(1) { expect(client.read(1)).to eq "1" }
+ Timeout::timeout(2) { expect(client.read(1)).to eq "2" }
+ ensure
+ actor.terminate if actor.alive?
+ end
+ end
+ end
+
context "outside Celluloid::IO" do
it "should be blocking" do
with_tcp_server(example_port) do |subject|
expect(Celluloid::IO).not_to be_evented
end