Repository navigation
test(rails): isolate app-booting specs in forked processes #3239
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
Merged
+409
−34
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
62a45af
test(rails): isolate specs in forked processes
solnic a679c72
fix(rails): check isolated child exit status
solnic 993af2e
fix(rails): disconnect test SQLite before forking
solnic b122fcb
fix(rails): honor fail-fast in isolated groups
solnic ccf1d45
fix(rails): bypass exit hooks in isolated children
solnic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| parent_pid = Process.pid | ||
| at_exit { warn "inherited exit hook ran in isolation child" if Process.pid != parent_pid } | ||
|
|
||
| RSpec.describe "isolation child error", isolate: true do | ||
| it "finishes the example before output flushing raises" do | ||
| def $stdout.flush | ||
| raise IOError, "could not flush child output" | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe "isolation child exit", isolate: true do | ||
| it "finishes the example before the child fails" do | ||
| def $stdout.flush | ||
| exit!(7) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| parent_connection = nil | ||
| RSpec.configure do |config| | ||
| config.before(:suite) do | ||
| ActiveRecord::Base.connection_pool.with_connection do |connection| | ||
| parent_connection = connection.raw_connection | ||
| end | ||
| end | ||
| end | ||
|
|
||
| RSpec.describe "isolation database", isolate: true do | ||
| it "opens its own connection to the test database" do | ||
| ActiveRecord::Base.connection_pool.with_connection do |connection| | ||
| expect(connection.raw_connection).not_to equal(parent_connection) | ||
| expect(connection.select_value("SELECT 1")).to eq(1) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe "earlier group" do | ||
| it "uses one failure from the budget" do | ||
| raise "failure from the earlier group" | ||
| end | ||
| end | ||
|
|
||
| RSpec.describe "isolated group", isolate: :group do | ||
| it "uses the remaining failure from the budget" do | ||
| raise "failure from the isolated group" | ||
| end | ||
|
|
||
| it "would exceed the failure budget" do | ||
| raise "example ran after the failure limit" | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "open3" | ||
|
|
||
| RSpec.describe "isolated spec runner" do | ||
| it "fails the run when the child exits unsuccessfully after reporting a result" do | ||
| skip "fork is unavailable" unless Process.respond_to?(:fork) | ||
|
|
||
| fixture = File.expand_path("../fixtures/isolation_child_exit.rb", __dir__) | ||
| stdout, stderr, status = Open3.capture3(RbConfig.ruby, "-S", "rspec", fixture) | ||
|
|
||
| expect(status.exitstatus).to eq(1), stdout + stderr | ||
| expect(stdout).to match(/isolated spec child failed.*exit 7/) | ||
| end | ||
|
|
||
| it "reports a child exception without running inherited exit hooks" do | ||
| skip "fork is unavailable" unless Process.respond_to?(:fork) | ||
|
|
||
| fixture = File.expand_path("../fixtures/isolation_child_error.rb", __dir__) | ||
| stdout, stderr, status = Open3.capture3(RbConfig.ruby, "-S", "rspec", fixture) | ||
|
|
||
| expect(status.exitstatus).to eq(1), stdout + stderr | ||
| expect(stderr).to include("could not flush child output") | ||
| expect(stderr).not_to include("inherited exit hook ran in isolation child") | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "open3" | ||
|
|
||
| RSpec.describe "isolated SQLite specs" do | ||
| it "starts the child without an inherited database connection" do | ||
| skip "fork is unavailable" unless Process.respond_to?(:fork) | ||
|
|
||
| fixture = File.expand_path("../fixtures/isolation_database.rb", __dir__) | ||
| stdout, stderr, status = Open3.capture3(RbConfig.ruby, "-S", "rspec", fixture) | ||
|
|
||
| expect(status.exitstatus).to eq(0), stdout + stderr | ||
| expect(stdout).to include("1 example, 0 failures") | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "open3" | ||
|
|
||
| RSpec.describe "isolated group fail-fast" do | ||
| it "counts earlier failures toward the limit within an isolated group" do | ||
| skip "fork is unavailable" unless Process.respond_to?(:fork) | ||
|
|
||
| fixture = File.expand_path("../fixtures/isolation_fail_fast.rb", __dir__) | ||
| stdout, stderr, status = Open3.capture3(RbConfig.ruby, "-S", "rspec", "--order", "defined", "--fail-fast=2", fixture) | ||
|
|
||
| expect(status.exitstatus).to eq(1), stdout + stderr | ||
| expect(stdout).to include("2 examples, 2 failures") | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.