Skip to content

Commit

Permalink
RUBY-3405 make sure the cluster time is applied to new sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
jamis committed Mar 2, 2024
1 parent 8254134 commit 40b4cd5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
19 changes: 14 additions & 5 deletions spec/runners/transactions/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ def admin_support_client
def test_client
@test_client ||= begin
sdam_proc = lambda do |test_client|
test_client.subscribe(Mongo::Monitoring::COMMAND, command_subscriber)

test_client.subscribe(Mongo::Monitoring::TOPOLOGY_OPENING, sdam_subscriber)
test_client.subscribe(Mongo::Monitoring::SERVER_OPENING, sdam_subscriber)
test_client.subscribe(Mongo::Monitoring::SERVER_DESCRIPTION_CHANGED, sdam_subscriber)
Expand Down Expand Up @@ -179,7 +177,11 @@ def test_client
database: @spec.database_name,
auth_source: SpecConfig.instance.auth_options[:auth_source] || 'admin',
sdam_proc: sdam_proc,
).merge(@client_options))
).merge(@client_options)).tap do |client|
# DRIVERS-2816, adjusted for legacy spec runner
@cluster_time = client.command(ping: 1).cluster_time
client.subscribe(Mongo::Monitoring::COMMAND, command_subscriber)
end
end
end

Expand Down Expand Up @@ -358,12 +360,19 @@ def resolve_target(client, operation)
end
end

def new_session(options)
test_client.start_session(options || {}).tap do |s|
# DRIVERS-2816, adjusted for legacy spec runner
s.advance_cluster_time(@cluster_time)
end
end

def session0
@session0 ||= test_client.start_session(@session_options[:session0] || {})
@session0 ||= new_session(@session_options[:session0])
end

def session1
@session1 ||= test_client.start_session(@session_options[:session1] || {})
@session1 ||= new_session(@session_options[:session1])
end
end
end
Expand Down
9 changes: 8 additions & 1 deletion spec/runners/unified/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ def generate_entities(es)
opts = {}
end

client.start_session(**opts)
client.start_session(**opts).tap do |session|
session.advance_cluster_time(@cluster_time)
end
when 'clientEncryption'
client_encryption_opts = spec.use!('clientEncryptionOpts')
key_vault_client = entities.get(:client, client_encryption_opts['keyVaultClient'])
Expand Down Expand Up @@ -342,6 +344,11 @@ def set_initial_data
raise NotImplementedError, "Unhandled spec keys: #{spec}"
end
end

# the cluster time is used to advance the cluster time of any
# sessions created during this test.
# -> see DRIVERS-2816
@cluster_time = root_authorized_client.command(ping: 1).cluster_time
end

def run
Expand Down

0 comments on commit 40b4cd5

Please sign in to comment.