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

[7-0-stable] Backport "Fix flaky test in railties/test/applications/rake/dbs_test.rb" #48635

Merged
merged 1 commit into from Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions railties/test/application/rake/dbs_test.rb
Expand Up @@ -471,7 +471,7 @@ def db_schema_cache_dump

test "db:schema:cache:dump dumps virtual columns" do
Dir.chdir(app_path) do
use_postgresql(database_name: "railties_db")
use_postgresql
rails "db:drop", "db:create"

rails "runner", <<~RUBY
Expand Down Expand Up @@ -759,12 +759,12 @@ def db_fixtures_load(expected_database)

test "db:prepare creates test database if it does not exist" do
Dir.chdir(app_path) do
use_postgresql(database_name: "railties_db")
db_name = use_postgresql
rails "db:drop", "db:create"
rails "runner", "ActiveRecord::Base.connection.drop_database(:railties_db_test)"
rails "runner", "ActiveRecord::Base.connection.drop_database(:#{db_name}_test)"

output = rails("db:prepare")
assert_match(%r{Created database 'railties_db_test'}, output)
assert_match(%r{Created database '#{db_name}_test'}, output)
end
ensure
rails "db:drop" rescue nil
Expand Down
4 changes: 3 additions & 1 deletion railties/test/isolation/abstract_unit.rb
Expand Up @@ -458,7 +458,8 @@ def use_frameworks(arr)
$:.reject! { |path| path =~ %r'/(#{to_remove.join('|')})/' }
end

def use_postgresql(multi_db: false, database_name: "railties_#{Process.pid}")
def use_postgresql(multi_db: false)
database_name = "railties_#{Process.pid}"
if multi_db
File.open("#{app_path}/config/database.yml", "w") do |f|
f.puts <<-YAML
Expand Down Expand Up @@ -490,6 +491,7 @@ def use_postgresql(multi_db: false, database_name: "railties_#{Process.pid}")
YAML
end
end
database_name
end
end

Expand Down