Skip to content

Commit

Permalink
Fix flaky railties/test/applications/rake/dbs_test.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Jan 11, 2023
1 parent d453eb5 commit cdb21a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions railties/test/application/rake/dbs_test.rb
Expand Up @@ -479,7 +479,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 @@ -773,12 +773,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 @@ -465,7 +465,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 @@ -497,6 +498,7 @@ def use_postgresql(multi_db: false, database_name: "railties_#{Process.pid}")
YAML
end
end
database_name
end
end

Expand Down

0 comments on commit cdb21a1

Please sign in to comment.