class ActionController::LiveStreamTest::TestController
Attributes
error_latch[RW]
latch[RW]
tc[RW]
Public Class Methods
controller_path()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 120 def self.controller_path "test" end
Public Instance Methods
bad_request_error()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 211 def bad_request_error raise ActionController::BadRequest end
basic_stream()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 139 def basic_stream response.headers["Content-Type"] = "text/event-stream" %w{ hello world }.each do |word| response.stream.write word end response.stream.close end
blocking_stream()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 147 def blocking_stream response.headers["Content-Type"] = "text/event-stream" %w{ hello world }.each do |word| response.stream.write word latch.wait end response.stream.close end
default_header()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 134 def default_header response.stream.write "<html><body>hi</body></html>" response.stream.close end
exception_in_controller()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 207 def exception_in_controller raise Exception, "Exception in controller" end
exception_in_exception_callback()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 215 def exception_in_exception_callback response.headers["Content-Type"] = "text/event-stream" response.stream.on_error do raise "We need to go deeper." end response.stream.write "" response.stream.write params[:widget][:didnt_check_for_nil] end
exception_in_view()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 186 def exception_in_view render "doesntexist" end
exception_in_view_after_commit()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 190 def exception_in_view_after_commit response.stream.write "" render "doesntexist" end
exception_with_callback()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 195 def exception_with_callback response.headers["Content-Type"] = "text/event-stream" response.stream.on_error do response.stream.write %(data: "500 Internal Server Error"\n\n) response.stream.close end response.stream.write "" # make sure the response is committed raise "An exception occurred..." end
ignore_client_disconnect()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 249 def ignore_client_disconnect response.stream.ignore_disconnect = true response.stream.write "" # commit # These writes will be ignored 15.times do response.stream.write "x" end logger.info "Work complete" latch.count_down end
overfill_buffer_and_die()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 224 def overfill_buffer_and_die logger = ActionController::Base.logger || Logger.new($stdout) response.stream.on_error do logger.warn "Error while streaming." error_latch.count_down end # Write until the buffer is full. It doesn't expose that # information directly, so we must hard-code its size: 10.times do response.stream.write "." end # .. plus one more, because the #each frees up a slot: response.stream.write "." latch.count_down # This write will block, and eventually raise response.stream.write "x" 20.times do response.stream.write "." end end
render_text()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 130 def render_text render plain: "zomg" end
thread_locals()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 172 def thread_locals tc.assert_equal "aaron", Thread.current[:setting] response.headers["Content-Type"] = "text/event-stream" %w{ hello world }.each do |word| response.stream.write word end response.stream.close end
with_stale()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 182 def with_stale render plain: "stale" if stale?(etag: "123", template: false) end
write_sleep_autoload()
click to toggle source
# File actionpack/test/controller/live_stream_test.rb, line 156 def write_sleep_autoload path = File.expand_path("../fixtures", __dir__) ActiveSupport::Dependencies.autoload_paths << path response.headers["Content-Type"] = "text/event-stream" response.stream.write "before load" sleep 0.01 silence_warning do ::LoadMe end response.stream.close latch.count_down ActiveSupport::Dependencies.autoload_paths.reject! { |p| p == path } end