Skip to content

Commit 86ed033

Browse files
committed
fix parallel test
1 parent 264c892 commit 86ed033

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

test/closure_tree/generator_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def test_generator_output_with_namespaced_model_with_slash
4242

4343
def test_should_run_all_tasks_in_generator_without_errors
4444
gen = generator %w[tag]
45-
capture_io { gen.invoke_all }
45+
output = capture_io { gen.invoke_all }
46+
assert output, "Generator should complete without errors"
4647
end
4748
end
4849
end

test/test_helper.rb

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,39 @@
1919
ENV['WITH_ADVISORY_LOCK_PREFIX'] ||= SecureRandom.hex
2020

2121
# Parse database URL and establish connection
22-
if database_url.start_with?('sqlite3://')
22+
connection_config = if database_url.start_with?('sqlite3://')
2323
# SQLite needs special handling
2424
if database_url == 'sqlite3:///:memory:'
25-
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
25+
{ adapter: 'sqlite3', database: ':memory:' }
2626
else
2727
# Create a temporary database file
2828
db_file = File.join(Dir.tmpdir, "closure_tree_test_#{SecureRandom.hex}.sqlite3")
29-
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: db_file)
29+
{ adapter: 'sqlite3', database: db_file }
3030
end
3131
elsif database_url.start_with?('mysql2://')
3232
# Parse MySQL URL: mysql2://root:root@0/closure_tree_test
3333
# The @0 means localhost in GitHub Actions
34-
fixed_url = database_url.gsub('@0/', '@127.0.0.1/')
35-
ActiveRecord::Base.establish_connection(fixed_url)
34+
database_url.gsub('@0/', '@127.0.0.1/')
3635
elsif database_url.start_with?('postgres://')
3736
# Parse PostgreSQL URL: postgres://closure_tree:closure_tree@0/closure_tree_test
3837
# The @0 means localhost in GitHub Actions
3938
fixed_url = database_url.gsub('@0/', '@127.0.0.1/')
4039
# PostgreSQL adapter expects 'postgresql://' not 'postgres://'
41-
fixed_url = fixed_url.gsub('postgres://', 'postgresql://')
42-
ActiveRecord::Base.establish_connection(fixed_url)
40+
fixed_url.gsub('postgres://', 'postgresql://')
4341
else
4442
# For other database URLs, use directly
45-
ActiveRecord::Base.establish_connection(database_url)
43+
database_url
44+
end
45+
46+
# Set connection pool size for parallel tests
47+
if connection_config.is_a?(Hash)
48+
connection_config[:pool] = 50
49+
connection_config[:checkout_timeout] = 10
50+
ActiveRecord::Base.establish_connection(connection_config)
51+
else
52+
# For URL-based configs, append pool parameters
53+
separator = connection_config.include?('?') ? '&' : '?'
54+
ActiveRecord::Base.establish_connection("#{connection_config}#{separator}pool=50&checkout_timeout=10")
4655
end
4756

4857
def env_db

0 commit comments

Comments
 (0)