|
19 | 19 | ENV['WITH_ADVISORY_LOCK_PREFIX'] ||= SecureRandom.hex |
20 | 20 |
|
21 | 21 | # Parse database URL and establish connection |
22 | | -if database_url.start_with?('sqlite3://') |
| 22 | +connection_config = if database_url.start_with?('sqlite3://') |
23 | 23 | # SQLite needs special handling |
24 | 24 | if database_url == 'sqlite3:///:memory:' |
25 | | - ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') |
| 25 | + { adapter: 'sqlite3', database: ':memory:' } |
26 | 26 | else |
27 | 27 | # Create a temporary database file |
28 | 28 | 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 } |
30 | 30 | end |
31 | 31 | elsif database_url.start_with?('mysql2://') |
32 | 32 | # Parse MySQL URL: mysql2://root:root@0/closure_tree_test |
33 | 33 | # 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/') |
36 | 35 | elsif database_url.start_with?('postgres://') |
37 | 36 | # Parse PostgreSQL URL: postgres://closure_tree:closure_tree@0/closure_tree_test |
38 | 37 | # The @0 means localhost in GitHub Actions |
39 | 38 | fixed_url = database_url.gsub('@0/', '@127.0.0.1/') |
40 | 39 | # 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://') |
43 | 41 | else |
44 | 42 | # 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") |
46 | 55 | end |
47 | 56 |
|
48 | 57 | def env_db |
|
0 commit comments