Skip to content

Commit

Permalink
Add Rails 6 streaming test routes
Browse files Browse the repository at this point in the history
Similar to the Rails 7 app, test these streaming responses for Rails 6.

Remove rack-mini-profiler, because the streaming won't work with it.
  • Loading branch information
tombruijn committed Feb 15, 2024
1 parent 5f125d5 commit 9d4b452
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
3 changes: 0 additions & 3 deletions ruby/rails6-mysql/app/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 4.1.0'
# Display performance information such as SQL time and flame graphs for each request in your browser.
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
gem 'rack-mini-profiler', '~> 2.0'
gem 'listen', '~> 3.3'
end

Expand Down
6 changes: 3 additions & 3 deletions ruby/rails6-mysql/app/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: /integration
specs:
appsignal (3.4.0)
appsignal (3.5.5)
rack

GEM
Expand Down Expand Up @@ -231,7 +231,7 @@ DEPENDENCIES
webpacker (~> 5.0)

RUBY VERSION
ruby 3.2.1p31
ruby 3.2.2p53

BUNDLED WITH
2.4.11
2.5.6
35 changes: 35 additions & 0 deletions ruby/rails6-mysql/app/app/controllers/tests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,39 @@ def error
def slow
sleep 3
end

class StreamingSlowBody
def each
sleep 1
yield "1"
sleep 1
yield "2"
sleep 1
yield "3"
sleep 1
yield "4"
end
end

def streaming_slow
headers["Content-Length"] = "4"
headers["Last-Modified"] = Time.now.httpdate
self.response_body = StreamingSlowBody.new
end

class StreamingErrorBody
def each
yield "1"
sleep 0.5
yield "2"
yield "3"
raise "Rails error in streaming body"
end
end

def streaming_error_in_body
headers["Content-Length"] = "4"
headers["Last-Modified"] = Time.now.httpdate
self.response_body = StreamingErrorBody.new
end
end
9 changes: 9 additions & 0 deletions ruby/rails6-mysql/app/app/views/tests/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1>Rails 6 mysql app</h1>

<ul>
<li><%= link_to "Slow request", slow_path %></li>
<li><%= link_to "Error request", error_path %></li>
<li><%= link_to "Slow streaming request", streaming_slow_path %></li>
<li><%= link_to "Streaming request with error", streaming_error_path %></li>
<li><%= link_to "Posts: resources with queies", posts_path %></li>
</ul>
4 changes: 4 additions & 0 deletions ruby/rails6-mysql/app/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Rails.application.routes.draw do
get "/slow", to: "tests#slow"
get "/error", to: "tests#error"
get "/streaming/slow", to: "tests#streaming_slow"
get "/streaming/error", to: "tests#streaming_error_in_body"

resources :posts, :except => %i[edit update destroy]

root to: "tests#index"
end

0 comments on commit 9d4b452

Please sign in to comment.