Namespace
Methods
A
C
T
Instance Public methods
assert_stream_closed()
# File actionpack/test/controller/live_stream_test.rb, line 242
def assert_stream_closed
  assert response.stream.closed?, 'stream should be closed'
  assert response.sent?, 'stream should be sent'
end
capture_log_output()
# File actionpack/test/controller/live_stream_test.rb, line 247
def capture_log_output
  output = StringIO.new
  old_logger, ActionController::Base.logger = ActionController::Base.logger, ActiveSupport::Logger.new(output)

  begin
    yield output
  ensure
    ActionController::Base.logger = old_logger
  end
end
test_abort_with_full_buffer()
# File actionpack/test/controller/live_stream_test.rb, line 300
def test_abort_with_full_buffer
  @controller.latch = ActiveSupport::Concurrency::Latch.new

  @request.parameters[:format] = 'plain'
  @controller.request  = @request
  @controller.response = @response

  got_error = ActiveSupport::Concurrency::Latch.new
  @response.stream.on_error do
    ActionController::Base.logger.warn 'Error while streaming'
    got_error.release
  end

  t = Thread.new(@response) { |resp|
    resp.await_commit
    _, _, body = resp.to_a
    body.each do |part|
      @controller.latch.await
      body.close
      break
    end
  }

  capture_log_output do |output|
    @controller.process :overfill_buffer_and_die
    t.join
    got_error.await
    assert_match 'Error while streaming', output.rewind && output.read
  end
end
test_async_stream()
# File actionpack/test/controller/live_stream_test.rb, line 278
def test_async_stream
  @controller.latch = ActiveSupport::Concurrency::Latch.new
  parts             = ['hello', 'world']

  @controller.request  = @request
  @controller.response = @response

  t = Thread.new(@response) { |resp|
    resp.await_commit
    resp.stream.each do |part|
      assert_equal parts.shift, part
      ol = @controller.latch
      @controller.latch = ActiveSupport::Concurrency::Latch.new
      ol.release
    end
  }

  @controller.process :blocking_stream

  assert t.join(3), 'timeout expired before the thread terminated'
end
test_bad_request_in_controller_before_streaming()
# File actionpack/test/controller/live_stream_test.rb, line 421
def test_bad_request_in_controller_before_streaming
  assert_raises(ActionController::BadRequest) do
    get :bad_request_error, format: 'text/event-stream'
  end
end
test_exception_callback_when_committed()
# File actionpack/test/controller/live_stream_test.rb, line 406
def test_exception_callback_when_committed
  capture_log_output do |output|
    get :exception_with_callback, format: 'text/event-stream'
    assert_equal %Q(data: "500 Internal Server Error"\n\n), response.body
    assert_match 'An exception occurred...', output.rewind && output.read
    assert_stream_closed
  end
end
test_exception_handling_html()
# File actionpack/test/controller/live_stream_test.rb, line 378
def test_exception_handling_html
  assert_raises(ActionView::MissingTemplate) do
    get :exception_in_view
  end

  capture_log_output do |output|
    get :exception_in_view_after_commit
    assert_match %r((window\.location = "/500\.html"</script></html>)$), response.body
    assert_match 'Missing template test/doesntexist', output.rewind && output.read
    assert_stream_closed
  end
  assert response.body
  assert_stream_closed
end
test_exception_handling_plain_text()
# File actionpack/test/controller/live_stream_test.rb, line 393
def test_exception_handling_plain_text
  assert_raises(ActionView::MissingTemplate) do
    get :exception_in_view, format: :json
  end

  capture_log_output do |output|
    get :exception_in_view_after_commit, format: :json
    assert_equal '', response.body
    assert_match 'Missing template test/doesntexist', output.rewind && output.read
    assert_stream_closed
  end
end
test_exception_in_controller_before_streaming()
# File actionpack/test/controller/live_stream_test.rb, line 415
def test_exception_in_controller_before_streaming
  assert_raises(ActionController::LiveStreamTest::Exception) do
    get :exception_in_controller, format: 'text/event-stream'
  end
end
test_exceptions_raised_handling_exceptions_and_committed()
# File actionpack/test/controller/live_stream_test.rb, line 427
def test_exceptions_raised_handling_exceptions_and_committed
  capture_log_output do |output|
    get :exception_in_exception_callback, format: 'text/event-stream'
    assert_equal '', response.body
    assert_match 'We need to go deeper', output.rewind && output.read
    assert_stream_closed
  end
end
test_ignore_client_disconnect()
# File actionpack/test/controller/live_stream_test.rb, line 331
def test_ignore_client_disconnect
  @controller.latch = ActiveSupport::Concurrency::Latch.new

  @controller.request  = @request
  @controller.response = @response

  t = Thread.new(@response) { |resp|
    resp.await_commit
    _, _, body = resp.to_a
    body.each do |part|
      body.close
      break
    end
  }

  capture_log_output do |output|
    @controller.process :ignore_client_disconnect
    t.join
    Timeout.timeout(3) do
      @controller.latch.await
    end
    assert_match 'Work complete', output.rewind && output.read
  end
end
test_live_stream_default_header()
# File actionpack/test/controller/live_stream_test.rb, line 364
def test_live_stream_default_header
  @controller.request  = @request
  @controller.response = @response
  @controller.process :default_header
  _, headers, _ = @response.prepare!
  assert headers['Content-Type']
end
test_render_text()
# File actionpack/test/controller/live_stream_test.rb, line 372
def test_render_text
  get :render_text
  assert_equal 'zomg', response.body
  assert_stream_closed
end
test_set_response!()
# File actionpack/test/controller/live_stream_test.rb, line 265
def test_set_response!
  @controller.set_response!(@request)
  assert_kind_of(Live::Response, @controller.response)
  assert_equal @request, @controller.response.request
end
test_stale_with_etag()
# File actionpack/test/controller/live_stream_test.rb, line 441
def test_stale_with_etag
  @request.if_none_match = Digest::MD5.hexdigest("123")
  get :with_stale
  assert_equal 304, @response.status.to_i
end
test_stale_without_etag()
# File actionpack/test/controller/live_stream_test.rb, line 436
def test_stale_without_etag
  get :with_stale
  assert_equal 200, @response.status.to_i
end
test_thread_locals_get_copied()
# File actionpack/test/controller/live_stream_test.rb, line 356
def test_thread_locals_get_copied
  @controller.tc = self
  Thread.current[:originating_thread] = Thread.current.object_id
  Thread.current[:setting]            = 'aaron'

  get :thread_locals
end
test_write_to_stream()
# File actionpack/test/controller/live_stream_test.rb, line 271
def test_write_to_stream
  @controller = TestController.new
  get :basic_stream
  assert_equal "helloworld", @response.body
  assert_equal 'text/event-stream', @response.headers['Content-Type']
end