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

Version Path
cool.io-1.9.0 spec/udp_socket_spec.rb
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/spec/udp_socket_spec.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/spec/udp_socket_spec.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/spec/udp_socket_spec.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/spec/udp_socket_spec.rb
cool.io-1.8.0 spec/udp_socket_spec.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/cool.io-1.7.1/spec/udp_socket_spec.rb
cool.io-1.7.1-x86-mingw32 spec/udp_socket_spec.rb
cool.io-1.7.1-x64-mingw32 spec/udp_socket_spec.rb
cool.io-1.7.1 spec/udp_socket_spec.rb
cool.io-1.7.0 spec/udp_socket_spec.rb
cool.io-1.6.1 spec/udp_socket_spec.rb
cool.io-1.6.0-x64-mingw32 spec/udp_socket_spec.rb
cool.io-1.6.0-x86-mingw32 spec/udp_socket_spec.rb
cool.io-1.6.0 spec/udp_socket_spec.rb
cool.io-1.5.4-x64-mingw32 spec/udp_socket_spec.rb
cool.io-1.5.4-x86-mingw32 spec/udp_socket_spec.rb
cool.io-1.5.4 spec/udp_socket_spec.rb
cool.io-1.5.3-x86-mingw32 spec/udp_socket_spec.rb
cool.io-1.5.3-x64-mingw32 spec/udp_socket_spec.rb