Namespace
Methods
A
C
S
T
Instance Public methods
assert_stream_closed()
# File actionpack/test/controller/live_stream_test.rb, line 247
def assert_stream_closed
  assert response.stream.closed?, 'stream should be closed'
  assert response.committed?,     'response should be committed'
  assert response.sent?,          'response should be sent'
end
capture_log_output()
# File actionpack/test/controller/live_stream_test.rb, line 253
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
setup()
# File actionpack/test/controller/live_stream_test.rb, line 264
def setup
  super

  def @controller.new_controller_thread
    Thread.new { yield }
  end
end
test_abort_with_full_buffer()
# File actionpack/test/controller/live_stream_test.rb, line 305
def test_abort_with_full_buffer
  @controller.latch = Concurrent::CountDownLatch.new
  @controller.error_latch = Concurrent::CountDownLatch.new

  capture_log_output do |output|
    get :overfill_buffer_and_die, :format => 'plain'

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

    t.join
    @controller.error_latch.wait
    assert_match 'Error while streaming', output.rewind && output.read
  end
end
test_async_stream()
# File actionpack/test/controller/live_stream_test.rb, line 284
def test_async_stream
  rubinius_skip "https://github.com/rubinius/rubinius/issues/2934"

  @controller.latch = Concurrent::CountDownLatch.new
  parts             = ['hello', 'world']

  get :blocking_stream

  t = Thread.new(response) { |resp|
    resp.await_commit
    resp.stream.each do |part|
      assert_equal parts.shift, part
      ol = @controller.latch
      @controller.latch = Concurrent::CountDownLatch.new
      ol.count_down
    end
  }

  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 419
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 398
def test_exception_callback_when_committed
  current_threads = Thread.list

  capture_log_output do |output|
    get :exception_with_callback, format: 'text/event-stream'

    # Wait on the execution of all threads
    (Thread.list - current_threads).each(&:join)

    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 370
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 385
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 413
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 425
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 328
def test_ignore_client_disconnect
  @controller.latch = Concurrent::CountDownLatch.new

  capture_log_output do |output|
    get :ignore_client_disconnect

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

    t.join
    Timeout.timeout(3) do
      @controller.latch.wait
    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 359
def test_live_stream_default_header
  get :default_header
  assert response.headers['Content-Type']
end
test_render_text()
# File actionpack/test/controller/live_stream_test.rb, line 364
def test_render_text
  get :render_text
  assert_equal 'zomg', response.body
  assert_stream_closed
end
test_stale_with_etag()
# File actionpack/test/controller/live_stream_test.rb, line 439
def test_stale_with_etag
  @request.if_none_match = %Q(W/"#{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 434
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 351
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 278
def test_write_to_stream
  get :basic_stream
  assert_equal "helloworld", @response.body
  assert_equal 'text/event-stream', @response.headers['Content-Type']
end