Sha256: fc843954d574abfdd18d472ce8d1f1f9c980d8f1f3f74be8ce4d9ab3c20c1f64
Contents?: true
Size: 1.12 KB
Versions: 45
Compression:
Stored size: 1.12 KB
Contents
require File.expand_path('../spec_helper', __FILE__) describe "Coolio::UDPSocket" do let :loop do Coolio::Loop.new end before :each do @echo = UDPSocket.open @echo.bind nil, 0 @port = @echo.addr[1] @running = true @echo_thread = Thread.new do while @running begin msg, sender = @echo.recvfrom_nonblock(3) @echo.send(msg + "bbb", 0, sender[3], sender[1]) rescue IO::WaitReadable end Thread.pass end end end after :each do @running = false @echo_thread.join @echo.close end class Readable < Cool.io::IOWatcher attr :socket, :received def initialize @socket = UDPSocket.new super(@socket) end def on_readable @received = @socket.recvfrom_nonblock(6).first end end it "receive message #on_readable 5 times" do 5.times do begin r = Readable.new r.socket.send "aaa", 0, "localhost", @port loop.attach r loop.run_once expect(r.received).to eq "aaabbb" ensure r.detach end end end end
Version data entries
45 entries across 45 versions & 6 rubygems