Sha256: d2846bc776df54a197d91fefd80a80da8adb395c4dc1df244bc3bc5d06814109

Contents?: true

Size: 1.22 KB

Versions: 8

Compression:

Stored size: 1.22 KB

Contents

require 'libuv'


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

		@loop = Libuv::Loop.default
		@call = @loop.pipe
		@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
			p "Failed with: #{reason.message}\n#{reason.backtrace.join("\n")}\n"
		end
	end
	
	it "Should call the async function from the thread pool stopping the counter" do
		@loop.run { |logger|
			logger.progress do |level, errorid, error|
				begin
					p "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
				rescue Exception
					p 'error in logger'
				end
			end

			@count = 0

			timer = @loop.timer do
				@count += 1
			end
			timer.start(0, 200)

			callback = @loop.async do
				stopper = @loop.timer do
					timer.close
					callback.close
					stopper.close
					@timeout.close
					@loop.stop
				end
				stopper.start(1000)
				callback.close
			end

			@loop.work(proc {
				callback.call
			}).catch do |err|
				@general_failure << err
			end
		}

		expect(@general_failure).to eq([])
		expect(@count < 7 && @count > 3).to eq(true)
	end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
libuv-2.0.12 spec/async_spec.rb
libuv-2.0.11 spec/async_spec.rb
libuv-2.0.10 spec/async_spec.rb
libuv-2.0.9 spec/async_spec.rb
libuv-2.0.8 spec/async_spec.rb
libuv-2.0.6 spec/async_spec.rb
libuv-2.0.5 spec/async_spec.rb
libuv-2.0.4 spec/async_spec.rb