Skip to content

Commit e04a908

Browse files
committed
Use _N as a parallel tests databases suffixes
1 parent 65afe78 commit e04a908

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

activerecord/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
* Use `_N` as a parallel tests databases suffixes
2+
3+
Peviously, `-N` was used as a suffix. This can cause problems for RDBMSes
4+
which do not support dashes in database names.
5+
6+
*fatkodima*
7+
18
* Remember when a database connection has recently been verified (for
29
two seconds, by default), to avoid repeated reverifications during a
310
single request.

activerecord/lib/active_record/test_databases.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def self.create_and_load_schema(i, env_name:)
1212
old, ENV["VERBOSE"] = ENV["VERBOSE"], "false"
1313

1414
ActiveRecord::Base.configurations.configs_for(env_name: env_name).each do |db_config|
15-
db_config._database = "#{db_config.database}-#{i}"
15+
db_config._database = "#{db_config.database}_#{i}"
1616

1717
ActiveRecord::Tasks::DatabaseTasks.reconstruct_from_schema(db_config, ActiveRecord.schema_format, nil)
1818
end

activerecord/test/cases/test_databases_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_databases_are_created
1414
}
1515

1616
base_db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
17-
expected_database = "#{base_db_config.database}-2"
17+
expected_database = "#{base_db_config.database}_2"
1818

1919
ActiveRecord::Tasks::DatabaseTasks.stub(:reconstruct_from_schema, ->(db_config, _, _) {
2020
assert_equal expected_database, db_config.database
@@ -37,7 +37,7 @@ def test_create_databases_after_fork
3737

3838
idx = 42
3939
base_db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
40-
expected_database = "#{base_db_config.database}-#{idx}"
40+
expected_database = "#{base_db_config.database}_#{idx}"
4141

4242
ActiveRecord::Tasks::DatabaseTasks.stub(:reconstruct_from_schema, ->(db_config, _, _) {
4343
assert_equal expected_database, db_config.database

activesupport/lib/active_support/test_case.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def test_order
5252
# is forked. For each process a new database will be created suffixed
5353
# with the worker number.
5454
#
55-
# test-database-0
56-
# test-database-1
55+
# test-database_0
56+
# test-database_1
5757
#
5858
# If <tt>ENV["PARALLEL_WORKERS"]</tt> is set the workers argument will be ignored
5959
# and the environment variable will be used instead. This is useful for CI

guides/source/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ $ PARALLEL_WORKERS=15 bin/rails test
589589

590590
When parallelizing tests, Active Record automatically handles creating a database and loading the schema into the database for each
591591
process. The databases will be suffixed with the number corresponding to the worker. For example, if you
592-
have 2 workers the tests will create `test-database-0` and `test-database-1` respectively.
592+
have 2 workers the tests will create `test-database_0` and `test-database_1` respectively.
593593

594594
If the number of workers passed is 1 or fewer the processes will not be forked and the tests will not
595595
be parallelized and they will use the original `test-database` database.

0 commit comments

Comments
 (0)