Skip to content

Commit f9872c3

Browse files
authored
Improve upon test suite flakiness (#327)
* Make `turbo_test.rb` with Rails' generated `test_helper.rb` > Something in the test suite configuration is preventing the database > from being wiped between test runs. This results in state leaking > between tests. As a result, our Continuous Integration tests are flaky. > > - [#248][] As a follow-up to the [short-term solution][] shipped in [#248][], this commit attempts to make the `test/turbo_test.rb` file's setup consistent with the test harness setup generated by Rails' [engine generator][] code. To that end, this commit: * renames the `test/turbo_test.rb` file to `test/test_helper.rb` * omits one-off `require` calls for particular dependencies * re-orders the require calls so that the `../test/dummy/config/environment` file is required ahead of the `rails/test_help` file [engine generator]: https://github.com/rails/rails/blob/3c48b4030adbded21bebaa0d78254216cca48a6e/railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt [#248]: #248 [short-term solution]: c2dc5b1 * Use Ruby 2.7 argument forwarding Switching to argument forwarding addresses deprecation warnings like: ``` hotwired/turbo-rails/test/streams/streams_channel_test.rb:140: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call hotwired/turbo-rails/test/turbo_test.rb:14: warning: The called method `render' is defined here ``` * Tests: Load 6.1 defaults in Dummy Application Resolve deprecation warnings like: ``` Preparing test database DEPRECATION WARNING: Non-URL-safe CSRF tokens are deprecated. Use 6.1 defaults or above. (called from <top (required)> at /home/runner/work/turbo-rails/turbo-rails/test/dummy/config/initializers/inspect_helpers.rb:1) DEPRECATION WARNING: Using legacy connection handling is deprecated. Please set `legacy_connection_handling` to `false` in your application. The new connection handling does not support `connection_handlers` getter and setter. Read more about how to migrate at: https://guides.rubyonrails.org/active_record_multiple_databases.html#migrate-to-the-new-connection-handling (called from <top (required)> at /home/runner/work/turbo-rails/turbo-rails/test/test_helper.rb:6) ``` Since our GitHub CI matrix includes `6.1`, `7.0`, and `main`, CI's tests should run with at least the `6.1` defaults. * CI: Continue other executions on error Remove the `continue-on-error` configuration and instead allow other jobs complete in spite of failures. * Improve Flaky Test: Clear fields before filling in Resolve a flaky System Test by ensuring that an input is clear before filling in a new value. * Improve flaky tests: Broadcasts First, don't render HTML with the `<turbo-stream-source>` element. Instead, append the element when clicking a `<button>`.
1 parent 5040246 commit f9872c3

20 files changed

+77
-63
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jobs:
1111
- "6.1"
1212
- "7.0"
1313
- "main"
14-
continue-on-error: [ false ]
1514

1615
# Disabled until minitest relaxes its upper bound: https://github.com/seattlerb/minitest/pull/862
1716
# > minitest-5.14.2 requires ruby version < 3.1, >= 2.2, which is incompatible with the current version, ruby 3.1.0p-1
@@ -25,7 +24,7 @@ jobs:
2524

2625
name: ${{ format('Tests (Ruby {0}, Rails {1})', matrix.ruby-version, matrix.rails-version) }}
2726
runs-on: ubuntu-latest
28-
continue-on-error: ${{ matrix.continue-on-error }}
27+
continue-on-error: true
2928

3029
steps:
3130
- uses: actions/checkout@v1

test/application_system_test_case.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "turbo_test"
1+
require "test_helper"
22

33
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
44
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]

test/drive/drive_helper_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "turbo_test"
1+
require "test_helper"
22

33
class Turbo::DriveHelperTest < ActionDispatch::IntegrationTest
44
test "opting out of the default cache" do
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<button type="button">
2+
<%= content %>
3+
4+
<script>
5+
document.currentScript.parentElement.addEventListener("click", ({ currentTarget }) => {
6+
for (const template of currentTarget.querySelectorAll("template")) {
7+
currentTarget.parentElement.insertBefore(template.content, currentTarget)
8+
}
9+
currentTarget.remove()
10+
})
11+
</script>
12+
13+
<template><%= yield %></template>
14+
</button>
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<h1>Echo Messages</h1>
22

3-
<%= turbo_stream_from "messages", channel: EchoChannel, data: {message: "Hello, world!"} %>
3+
<%= render "template_button", content: "Start listening for broadcasts" do %>
4+
<%= turbo_stream_from "messages", channel: EchoChannel, data: {message: "Hello, world!"} %>
5+
<% end %>
6+
47
<div id="messages">
58
</div>
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<h1>Messages</h1>
22

3-
<span id="message-count">
4-
<%= @messages.count %> messages sent
5-
</span>
3+
<%= render "template_button", content: "Start listening for broadcasts" do %>
4+
<%= turbo_stream_from "messages" %>
5+
<% end %>
66

7-
<%= turbo_stream_from "messages" %>
87
<div id="messages">
98
</div>
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<h1>Users::Profiles</h1>
22

3-
<%= turbo_stream_from "users_profiles" %>
4-
<div id="users_profiles"></div>
3+
<%= render "template_button", content: "Start listening for broadcasts" do %>
4+
<%= turbo_stream_from "users_profiles" %>
5+
<% end %>
6+
7+
<div id="users_profiles">
8+
</div>

test/dummy/config/application.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
module Dummy
1313
class Application < Rails::Application
1414
# Initialize configuration defaults for originally generated Rails version.
15-
config.load_defaults 6.0
15+
config.load_defaults 6.1
1616

1717
# Settings in config/environments/* take precedence over those specified here.
1818
# Application configuration can go into files in config/initializers

test/dummy/config/cable.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ development:
22
adapter: async
33

44
test:
5-
adapter: async
5+
adapter: inline
66

77
production:
88
adapter: redis

test/frames/frame_request_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "turbo_test"
1+
require "test_helper"
22

33
class Turbo::FrameRequestControllerTest < ActionDispatch::IntegrationTest
44
test "frame requests are rendered without a layout" do

0 commit comments

Comments
 (0)