Skip to content

Commit 5903ab9

Browse files
committed
Fix concurrent projector cache test to avoid DB queries in thread loop
Move database query outside thread loop to properly test concurrent access to the same document instance. This eliminates 1000 DB queries, reduces connection pool contention, and makes the test faster and more reliable. Addresses review comment: mongodb#6112 (comment)
1 parent ab4b7e3 commit 5903ab9

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

spec/mongoid/fields/performance_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,12 @@
443443

444444
it 'handles concurrent projector cache access safely' do
445445
band = Band.create!(name: 'Test')
446+
limited = Band.only(:name).find(band.id)
446447
errors = Concurrent::Array.new
447448

448449
threads = Array.new(10) do
449450
Thread.new do
450451
100.times do
451-
limited = Band.only(:name).find(band.id)
452452
limited.attribute_missing?('rating')
453453
rescue StandardError => e
454454
errors << e

0 commit comments

Comments
 (0)