Included Modules

Sinatra::Async::Test::Methods

Public Instance Methods

assert_async() click to toggle source
# File lib/sinatra/async/test.rb, line 68
def assert_async
  assert last_response.async?, "response not asynchronous. expected a status of -1 got #{last_response.status}"
end
async_close() click to toggle source

Simulate a user closing the connection before a response is sent.

# File lib/sinatra/async/test.rb, line 73
def async_close
  raise ArgumentError, 'please make a request first' unless last_request
  current_session.last_request.env['async.close'].succeed
end
async_continue() click to toggle source

Executes the pending asynchronous blocks, required for the aget/apost/etc blocks to run.

# File lib/sinatra/async/test.rb, line 80
def async_continue
  while b = app.options.async_schedules.shift
    b.call
  end
end
build_rack_mock_session() click to toggle source
# File lib/sinatra/async/test.rb, line 64
def build_rack_mock_session # XXX move me
  Sinatra::Async::Test::AsyncSession.new(app)
end
em_async_continue(timeout = 10) click to toggle source

Crank the eventmachine loop until a response is made, or timeout after a particular period, by default 10s. If the timeout is nil, no timeout will occur.

# File lib/sinatra/async/test.rb, line 89
def em_async_continue(timeout = 10)
  timed = false
  EM.run do
    async_continue
    em_hard_loop { EM.stop unless last_response.async? }
    EM.add_timer(timeout) { timed = true; EM.stop } if timeout
  end
  assert !timed, "asynchronous timeout after #{timeout} seconds"
end
em_hard_loop() click to toggle source

Uses EM.tick_loop or a periodic timer to check for changes

# File lib/sinatra/async/test.rb, line 100
def em_hard_loop
  if EM.respond_to?(:tick_loop)
    EM.tick_loop { yield }
  else
    EM.add_periodic_timer(0.0001) { yield }
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.