From 458e0b7ef8bb7a75db0645c5d9e605efcc41656e Mon Sep 17 00:00:00 2001 From: karezche <64801825+karenc-bq@users.noreply.github.com> Date: Thu, 15 Oct 2026 15:32:46 -0700 Subject: [PATCH] fix: stabilize GDB switchover and performance integration tests --- .../container/gdb_switchover_failover_spec.rb | 4 ++ spec/integration/container/iam_auth_spec.rb | 12 ----- .../integration/container/performance_spec.rb | 2 +- .../container/utils/rds_test_utility.rb | 47 +++++++++++++++++-- .../container/utils/spec_helper.rb | 6 +-- .../integration/host/TestEnvironment.java | 1 + 6 files changed, 51 insertions(+), 21 deletions(-) diff --git a/spec/integration/container/gdb_switchover_failover_spec.rb b/spec/integration/container/gdb_switchover_failover_spec.rb index 1a7bcf49..13a00c37 100644 --- a/spec/integration/container/gdb_switchover_failover_spec.rb +++ b/spec/integration/container/gdb_switchover_failover_spec.rb @@ -345,6 +345,10 @@ def drive_txn_until_terminal(conn, timeout_secs:) # @param txn_scenario [Scenario, nil] optional open-transaction data-integrity scenario def run_planned_transition(from_writer_instance:, from_db_info:, target_cluster_id:, scenarios:, aggregate_label:, txn_scenario: nil) + # Let the previous transition settle before any connection is opened, so the wait does not count + # against the drive threads' failover deadlines. + rds_util.wait_until_global_members_available + conns = {} threads = {} results = {} diff --git a/spec/integration/container/iam_auth_spec.rb b/spec/integration/container/iam_auth_spec.rb index 2a34d963..e52c33a6 100644 --- a/spec/integration/container/iam_auth_spec.rb +++ b/spec/integration/container/iam_auth_spec.rb @@ -213,18 +213,6 @@ Integration::DriverHelper.close(drv, conn) if conn end - it 'raises IamAuthError when iam_region is missing for global endpoint' do - props_no_region = { - AwsAdvancedRubyDriverWrapper::PropertyDefinition::PLUGINS.name => 'iam', - AwsAdvancedRubyDriverWrapper::PropertyDefinition::GLOBAL_CLUSTER_INSTANCE_HOST_PATTERNS.name => - "[#{env.primary_region}]?.#{info.instance_endpoint_suffix}:#{writer.port}" - } - - expect do - Integration::DriverHelper.wrapper_connect(drv, **gdb_config, **props_no_region) - end.to raise_error(AwsAdvancedRubyDriverWrapper::Errors::IamAuthError, /unable to determine connection region/) - end - it 'connects to secondary cluster endpoint with IAM' do skip 'Secondary cluster endpoint not available' unless env.secondary_cluster_endpoint diff --git a/spec/integration/container/performance_spec.rb b/spec/integration/container/performance_spec.rb index d241b88a..2894cd00 100644 --- a/spec/integration/container/performance_spec.rb +++ b/spec/integration/container/performance_spec.rb @@ -30,7 +30,7 @@ PERF_INTER_ITERATION_SLEEP = ENV.fetch('INTER_ITERATION_SLEEP', '15').to_i PERF_FINISH_LATCH_TIMEOUT = 120 PERF_RECONNECT_TIMEOUT_SEC = 5 -PERF_SOCKET_TIMEOUT_PARAMS = [[30, 10_000], [30, 20_000], [30, 30_000]].freeze +PERF_SOCKET_TIMEOUT_PARAMS = [[30, 5_000], [30, 10_000], [30, 20_000]].freeze RSpec.describe 'Failover Performance', :integration, features: [Integration::TestEnvironmentFeatures::PERFORMANCE, diff --git a/spec/integration/container/utils/rds_test_utility.rb b/spec/integration/container/utils/rds_test_utility.rb index 86d7b126..0cb4cd8e 100644 --- a/spec/integration/container/utils/rds_test_utility.rb +++ b/spec/integration/container/utils/rds_test_utility.rb @@ -658,13 +658,52 @@ def switchover_global_cluster(target_cluster_id, timeout_secs: GLOBAL_TRANSITION target_arn = cluster_arn(target_cluster_id) TestUtils.logger.info("GDB switchover: #{global_cluster_id} -> #{target_cluster_id}") - @client.switchover_global_cluster( - global_cluster_identifier: global_cluster_id, - target_db_cluster_identifier: target_arn - ) + request_global_switchover(global_cluster_id, target_arn) wait_until_primary_cluster(target_cluster_id, timeout_secs: timeout_secs) end + # RDS rejects a switchover while the global cluster or a member is still settling from a previous + # transition, so wait for them to settle and retry the request, as request_cluster_failover does. + def request_global_switchover(global_cluster_id, target_arn, max_request_attempts: 10) + max_request_attempts.times do + wait_until_global_members_available + @client.switchover_global_cluster( + global_cluster_identifier: global_cluster_id, + target_db_cluster_identifier: target_arn + ) + return + rescue Aws::RDS::Errors::InvalidDBClusterStateFault, Aws::RDS::Errors::InvalidGlobalClusterStateFault => e + TestUtils.logger.warn("switchover_global_cluster request failed (#{e.message}), retrying") + sleep(GLOBAL_TRANSITION_POLL_SECS) + end + + raise "Failed to request a global switchover for #{global_cluster_id} after #{max_request_attempts} attempts" + end + + # Waits until the global cluster and every member cluster report 'available', querying each member + # in its own region. + def wait_until_global_members_available + env = TestEnvironment.current + wait_until_global_cluster_available(env.global_cluster_identifier) if env.global_cluster_identifier + [env.cluster_name, env.secondary_cluster_identifier].compact.each do |cluster_id| + util = cluster_id == env.secondary_cluster_identifier ? self.class.secondary_utility : self + util.wait_until_cluster_has_desired_status(cluster_id, 'available') + end + end + + def wait_until_global_cluster_available(global_cluster_id, timeout_secs: GLOBAL_TRANSITION_TIMEOUT_SECS) + deadline = Time.now + timeout_secs + loop do + status = @client.describe_global_clusters(global_cluster_identifier: global_cluster_id) + .global_clusters.first&.status + return if status == 'available' + + raise "Timeout waiting for global cluster #{global_cluster_id} to become available" if Time.now > deadline + + sleep(GLOBAL_TRANSITION_POLL_SECS) + end + end + # Polls the global cluster members until the expected region is home to the global writer. # +region_or_cluster_id+ may be a region id (e.g. 'us-west-2') or a cluster identifier. def wait_until_primary_region(region_or_cluster_id, timeout: GLOBAL_TRANSITION_TIMEOUT_SECS) diff --git a/spec/integration/container/utils/spec_helper.rb b/spec/integration/container/utils/spec_helper.rb index 94017692..81609b9a 100644 --- a/spec/integration/container/utils/spec_helper.rb +++ b/spec/integration/container/utils/spec_helper.rb @@ -41,13 +41,11 @@ props end - # Base IAM props — extends base_wrapper_props with IAM plugin + region. + # Base IAM props — extends base_wrapper_props with the IAM plugin. let(:base_iam_props) do - props = base_wrapper_props.merge( + base_wrapper_props.merge( AwsAdvancedRubyDriverWrapper::PropertyDefinition::PLUGINS.name => 'iam' ) - props[AwsAdvancedRubyDriverWrapper::PropertyDefinition::IAM_REGION.name] = env.primary_region if env.global_cluster_endpoint - props end let(:base_config) do diff --git a/spec/integration/host/src/test/java/integration/host/TestEnvironment.java b/spec/integration/host/src/test/java/integration/host/TestEnvironment.java index b9393e8f..8f5addcf 100644 --- a/spec/integration/host/src/test/java/integration/host/TestEnvironment.java +++ b/spec/integration/host/src/test/java/integration/host/TestEnvironment.java @@ -1644,6 +1644,7 @@ private static void createTestContainer(TestEnvironment env) { .withEnv("AWS_ACCESS_KEY_ID", env.awsAccessKeyId) .withEnv("AWS_SECRET_ACCESS_KEY", env.awsSecretAccessKey) .withEnv("AWS_SESSION_TOKEN", env.awsSessionToken) + .withEnv("AWS_REGION", env.info.getRegion()) .withEnv("KMS_KEY_ID", env.kmsKeyId); }