Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤫 Quiet down railties tests #49679

Merged
merged 4 commits into from
May 31, 2024
Merged

🤫 Quiet down railties tests #49679

merged 4 commits into from
May 31, 2024

Conversation

zzak
Copy link
Member

@zzak zzak commented Oct 17, 2023

This PR addressed several unrelated issues in the Railties test suite, in order to reduce the amount of noise.

After

$ bundle exec rake test >> railties_output_patched 2>&1
$ wc -l railties_output_patched
    1491 railties_output_patched

Before

$ bundle exec rake test >> railties_output_unpatched 2>&1
$ wc -l railties_output_unpatched
   19023 railties_output_unpatched

@rails-bot rails-bot bot added the railties label Oct 17, 2023
railties/test/application/configuration_test.rb Outdated Show resolved Hide resolved
railties/test/generators/app_generator_test.rb Outdated Show resolved Hide resolved
railties/test/generators/shared_generator_tests.rb Outdated Show resolved Hide resolved
railties/test/generators/shared_generator_tests.rb Outdated Show resolved Hide resolved
railties/test/isolation/abstract_unit.rb Outdated Show resolved Hide resolved
railties/test/application/configuration_test.rb Outdated Show resolved Hide resolved
railties/test/application/url_generation_test.rb Outdated Show resolved Hide resolved
railties/test/generators/app_generator_test.rb Outdated Show resolved Hide resolved
railties/test/generators/app_generator_test.rb Outdated Show resolved Hide resolved
railties/test/generators/app_generator_test.rb Outdated Show resolved Hide resolved
railties/test/generators/shared_generator_tests.rb Outdated Show resolved Hide resolved
railties/test/isolation/abstract_unit.rb Outdated Show resolved Hide resolved
railties/test/isolation/abstract_unit.rb Outdated Show resolved Hide resolved
@zzak zzak force-pushed the railties-quiet branch 8 times, most recently from f0c5ac3 to 66556bc Compare October 23, 2023 21:52
Comment on lines 731 to 830
command_check = -> command, *_ do
if command == "importmap:install"
flunk "`importmap:install` expected to not be called."
end
end
assert_nil @rails_commands, "`importmap:install` expected to not be called."

generator.stub(:rails_command, command_check) do
run_generator_instance
end
run_generator_instance
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, you are asserting before running the generator, so @rails_commands will always be nil.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathanhefner Nice catch!

I thought about this, but can you think of an elegant way to assert neither of these commands are called?

--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -728,10 +728,11 @@ def test_skip_active_job_option
   def test_skip_javascript_option
     generator([destination_root], skip_javascript: true)

-    assert_nil @rails_commands, "`importmap:install` expected to not be called."
-
     run_generator_instance

+    assert_not_includes @rails_commands, "importmap:install", "`importmap:install` expected to not be called."
+    assert_not_includes @rails_commands, "turbo:install stimulus:install", "`turbo:install stimulus:install` expected to not be called."

railties/test/generators/app_generator_test.rb Outdated Show resolved Hide resolved
railties/test/generators/app_generator_test.rb Outdated Show resolved Hide resolved
railties/test/generators/app_generator_test.rb Outdated Show resolved Hide resolved
railties/test/generators/app_generator_test.rb Outdated Show resolved Hide resolved
Comment on lines 892 to 1004
def test_default_generator_executes_all_rails_commands
run_generator_and_bundler [destination_root]

expected_commands = [
"credentials:diff --enroll", "importmap:install", "turbo:install stimulus:install"
]
assert_equal expected_commands, @rails_commands
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test is necessary. test_generator_configures_decrypted_diffs_by_default already asserts the result of credentials:diff --enroll, and the tests you've modified cover the other commands. Additionally, this test is brittle. We would have to update it whenever we add or remove and rails_command calls in the app generator.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to make sure that inserting a random rails_command "lol" somewhere will trip something somewhere in the test suite, and not only when you run it live, same goes for the empty test case.

railties/test/generators/plugin_generator_test.rb Outdated Show resolved Hide resolved
railties/test/generators/shared_generator_tests.rb Outdated Show resolved Hide resolved
@zzak zzak force-pushed the railties-quiet branch 2 times, most recently from 6b79ec5 to 81350b3 Compare October 31, 2023 05:46
zzak added a commit to zzak/stimulus-rails that referenced this pull request Jan 11, 2024
This commit adds test coverage for the installer Rake task and application template. The installer is run against a freshly generated Rails app using the version of Rails that is currently loaded. Thus the installer can be tested with different versions of Rails in CI.

Similar to rails/importmap-rails#206 for stimulus-rails

The motivation is to be able to move these tests from railties, see: rails/rails#49679

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
zzak added a commit to zzak/stimulus-rails that referenced this pull request Jan 11, 2024
This commit adds test coverage for the installer Rake task and application template. The installer is run against a freshly generated Rails app using the version of Rails that is currently loaded. Thus the installer can be tested with different versions of Rails in CI.

Similar to rails/importmap-rails#206 for stimulus-rails

The motivation is to be able to move these tests from railties, see: rails/rails#49679

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
zzak added a commit to zzak/turbo-rails that referenced this pull request Jan 11, 2024
This commit adds test coverage for the installer Rake task and application template. The installer is run against a freshly generated Rails app using the version of Rails that is currently loaded. Thus the installer can be tested with different versions of Rails in CI.

Similar to hotwired/stimulus-rails#136.

The motivation is to be able to move these tests from railties, see: rails/rails#49679

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
zzak added a commit to zzak/turbo-rails that referenced this pull request Apr 19, 2024
This commit adds test coverage for the installer Rake task and application template. The installer is run against a freshly generated Rails app using the version of Rails that is currently loaded. Thus the installer can be tested with different versions of Rails in CI.

Similar to hotwired/stimulus-rails#136.

The motivation is to be able to move these tests from railties, see: rails/rails#49679

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
@zzak zzak force-pushed the railties-quiet branch 2 times, most recently from 5ff74e6 to 01bf7c1 Compare May 18, 2024 10:35
zzak added 2 commits May 31, 2024 10:12
When rails#48269 was merged any gem installed during `rails new` which calls `app:template` would cause the install command to be executed and consequently `bundle install` would also run.

We want to avoid running these commands in our tests because they are very expensive.

It is up to the gem (importmap, etc) to test the behavior of the install command, not railties.

Before

```
$ bin/test test/generators/plugin_generator_test.rb test/generators/app_generator_test.rb
Finished in 320.803659s, 0.8541 runs/s, 7.1913 assertions/s.
274 runs, 2307 assertions, 14 failures, 0 errors, 0 skips
```

After

```
Finished in 70.316250s, 3.9251 runs/s, 34.3164 assertions/s.
276 runs, 2413 assertions, 0 failures, 0 errors, 0 skips
```
The default of :info generates a ton of unnecessary noise in the railties logs.
Since we are stubbing bundle commands, we can avoid sprockets side-effects here.

This commit also fixes the tests for preservation of sprockets during `app:update`.

Due to propshaft being the default, this test was unnecessary.
This will make sure we have less tests to run since those are slow.

Generate the app once and run many assertions on it instead of generating
the same app multiple times.
@rafaelfranca rafaelfranca merged commit 64d5f8b into rails:main May 31, 2024
2 of 3 checks passed
@zzak zzak deleted the railties-quiet branch May 31, 2024 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants