Skip to content

Commit db406bb

Browse files
committed
fix(test): flaky encryption
Minimal set of test reproduction: ```sh COCKROACH_SKIP_LOAD_SCHEMA=1 SEED=13092 bundle exec rake test TESTOPTS="--name='/\A("\ "test_concurrent_insert_with_processes"\ "|test_uniqueness_validations_work_when_using_old_encryption_schemes"\ "|test_fixtures_get_encrypted_automatically"\ "|test_ciphertext_for_returns_the_ciphertext_of_a_value_when_the_record_is_new)\z/'" ``` It is important NOT TO run `ActiveRecord::Base.reset_column_information`. Some tests are eagerly loading information to prevent side effects [^1]. We could run `Avenger.reset_column_information` but we actually do not need it here. [^1]: See https://github.com/rails/rails/blob/v8.1.1/activerecord/test/cases/encryption/helper.rb#L115-L120
1 parent 1337a57 commit db406bb

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

test/cases/transactions_test.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ def validate_unique_username
1818
end
1919
end
2020

21-
def test_concurrent_insert_with_processes
22-
conn = ActiveRecord::Base.lease_connection
23-
conn.create_table :avengers, force: true do |t|
21+
def setup
22+
@conn = ActiveRecord::Base.lease_connection
23+
@conn.create_table :avengers, force: true do |t|
2424
t.string :name
2525
end
26-
ActiveRecord::Base.reset_column_information
26+
end
27+
28+
def teardown
29+
@conn.drop_table :avengers, if_exists: true
30+
end
2731

32+
def test_concurrent_insert_with_processes # corrupting #1
2833
avengers = %w[Hulk Thor Loki]
2934
Avenger.cyclic_barrier = Concurrent::CyclicBarrier.new(avengers.size - 1)
3035
Thread.current[:name] = "Main" # For debug logs.
@@ -41,8 +46,6 @@ def test_concurrent_insert_with_processes
4146
assert_equal avengers.size, Avenger.count
4247
ensure
4348
Thread.current[:name] = nil
44-
conn = ActiveRecord::Base.lease_connection
45-
conn.drop_table :avengers, if_exists: true
4649
end
4750
end
4851
end

0 commit comments

Comments
 (0)