Sha256: 9361b91eb718ad12a88732c4a1a0ae9cadf54a313d1eb24a5b52980d992c5692

Contents?: true

Size: 1.57 KB

Versions: 16

Compression:

Stored size: 1.57 KB

Contents

require 'libuv'
require 'thread'


describe Libuv::UDP do
	before :each do
		@log = []
		@general_failure = []

		@loop = Libuv::Loop.new
		@server = @loop.udp
		@client = @loop.udp
		@timeout = @loop.timer do
			@loop.stop
			@general_failure << "test timed out"
		end
		@timeout.start(5000)

		@loop.all(@server, @client, @timeout).catch do |reason|
			@general_failure << reason.inspect
		end
	end
	
	describe 'basic client server' do
		it "should send a ping and return a pong", :network => true do
			@loop.run { |logger|
				logger.progress do |level, errorid, error|
					begin
						@general_failure << "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n") if error.backtrace}\n"
					rescue Exception => e
						@general_failure << "error in logger #{e.inspect}"
					end
				end


				@server.bind('127.0.0.1', 34567)
				@server.progress do |data, ip, port, server|
					@log << data
					server.send(ip, port, 'pong')
				end
				@server.start_read

				# catch errors
				@server.catch do |reason|
					@general_failure << reason.inspect
				end


				# connect client to server
				@client.bind('127.0.0.1', 34568)
				@client.progress do |data, ip, port, client|
					@log << data
					client.close
				end
				@client.start_read
				@client.send('127.0.0.1', 34567, 'ping')

				# catch errors
				@client.catch do |reason|
					@general_failure << reason.inspect
				end

				# close the handle
				@client.finally do
					@server.close
					@loop.stop
				end
			}

			expect(@log).to eq(['ping', 'pong'])
			expect(@general_failure).to eq([])
		end
	end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
libuv-2.0.12 spec/udp_spec.rb
libuv-2.0.11 spec/udp_spec.rb
libuv-2.0.10 spec/udp_spec.rb
libuv-2.0.9 spec/udp_spec.rb
libuv-2.0.8 spec/udp_spec.rb
libuv-2.0.6 spec/udp_spec.rb
libuv-2.0.5 spec/udp_spec.rb
libuv-2.0.4 spec/udp_spec.rb
libuv-2.0.3 spec/udp_spec.rb
libuv-2.0.2 spec/udp_spec.rb
libuv-2.0.1 spec/udp_spec.rb
libuv-2.0.0 spec/udp_spec.rb
libuv-1.3.0 spec/udp_spec.rb
libuv-1.2.0 spec/udp_spec.rb
libuv-1.1.3 spec/udp_spec.rb
libuv-1.1.2 spec/udp_spec.rb