Repository navigation
test: assert blue/green switchover calls resume and are routed - #1370
Merged
Merged
Conversation
The Blue/Green switchover tests now check what #1352 broke, inside the one switchover each lane runs. Probes start on the phase the plugin publishes. An execute on an open blue connection and a new connect to a green instance, both started in IN_PROGRESS, must return within 60 s, after the phase moved on, and use at most 1.0 s of their thread's CPU. The 60 s is twice bg_connect_timeout_ms, which the tests pin at its 30 s default. A new connection to the blue endpoint opened in POST (and in PREPARATION, when sampled) must reach the substitute host the plugin's status lists for it. A call still in flight after 60 s is reported as a spin or as blocked from a thread CPU sample, so a hung wrapper fails the test instead of hanging the suite. The plugin's logger is held at INFO during the test, and after it while any test thread is still running, so a spinning call can't flood the report with debug records. The switchover metrics are printed before the verdict, and an error while printing them can't hide it. The old test asserted nothing about the wrapper's calls or where new connections went, left hung threads running, and could not finish under the harness's 600 s pytest timeout: it waited 6 minutes and then slept 12. It now waits until the switchover completes, bounded from the request, then for the RDS API to report completion. Every thread is a daemon and the joins share one deadline. The services container is built on the main thread before the monitor threads start: conftest releases it and its lazy re-initialisation isn't locked, so their first connects could find no monitor service. If the switchover is never requested, the failure names the wait result and any unhandled exceptions. The direct topology monitors now poll with autocommit on, as the plugin's own status connections do: without it MySQL's REPEATABLE READ kept returning the first snapshot, so they never saw the switchover complete. The async twin gets the same changes, unwraps AsyncBlueGreenPlugin instead of the sync class, and adds an execute probe on the blue cluster endpoint, through the connection that owns the status provider (the async status doesn't list instance endpoints). That probe takes the provider out of the shutdown hooks every async worker drains when it ends, and stops it itself, and its summary line shows the role and execute routing the plugin had for its host. The harness waits for an in-flight switchover to settle before it picks the cluster to delete, and also deletes a deployment whose switchover failed. It asks RDS for the cluster parameter group family of the engine version instead of assuming aurora-postgresql16, so the PostgreSQL task works on newer default versions, and it deletes that group when the cluster create fails. Covers #1352.
The switchover checks are now plain probes with one joined failure
message. An execute and a connect started in IN_PROGRESS must return
within 60 s and use at most 1.0 s of their thread's CPU, and a returned
execute must have been held until the plugin left IN_PROGRESS. The
first connection to the blue endpoint opened in POST must reach a green
server recorded before the switchover, through a host that is not the
dialled name. The PREPARATION sample, the /proc CPU sampling and the
message table are gone, the "Green node changed name" assert is
removed (certificates can change after the status shows completed, as
in the JDBC wrapper), and the timings live in test_timings.py.
Four Gradle tasks, test-bgd-{mysql,pg}-aurora-{sync,async}, build one
environment and one deployment each, and the Integration Tests workflow
runs them in a new job. The harness waits for a deployment to settle
through one method that also accepts invalid_configuration, treats a
deployment that is gone as settled, and falls back to the PostgreSQL
major version for the parameter group family.
…en it reconnects by IP
JuanLeee
marked this pull request as ready for review
November 20, 2026 18:11
karenc-bq
reviewed
Nov 24, 2026
| path: ./tests/integration/container/reports | ||
| retention-days: 5 | ||
|
|
||
| blue-green-integration-tests: |
Contributor
There was a problem hiding this comment.
Can we keep this as a separate workflow?
Contributor
Author
There was a problem hiding this comment.
Created separate workflow but runs when merging pr
Move the blue-green-integration-tests job out of integration_tests.yml into blue_green_integration_tests.yml. The new workflow keeps the Integration Tests triggers (pushes to main, skipping docs-only changes, and workflow_dispatch), so the switchover tests still run on every merge to main. integration_tests.yml is the same as on main again.
karenc-bq
approved these changes
Nov 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
With
bgand an IAM-based auth plugin (iam,federated_auth,okta), a Blue/Green status monitor that reconnects by IP during a switchover can't open its connection, so the plugin's phase stops atPREPARATION: calls aren't held inIN_PROGRESSand new connections aren't sent to the green host inPOST. The asyncio monitor reconnects on every pass, so every async switchover with IAM hits it. The switchover integration tests onmaincouldn't show this or #1352, because they assert nothing about the wrapper's own calls or where new connections go and their fixed waits outlast the harness's 600 s pytest timeout. The async twin also looks for the sync plugin class, teardown chooses the cluster to delete from a status read before the switchover settled, the harness can't create an Aurora PostgreSQL Blue/Green cluster on its default version and no workflow runs them.This PR fixes the IAM host in both status monitors, makes
test_switchoverandtest_switchover_asynccheck what #1352 broke inside the one switchover each run makes, fixes what keeps the tests and the harness from finishing and runs the four switchover lanes in a new Blue/Green Integration Tests workflow.PREPARATIONthroughPOSTthe status monitors reconnect by IP, andBlueGreenStatusMonitor._open_connection_taskand itsaio/twin setIAM_HOSTto that IP.IamAuthUtils.get_iam_hostrejects an IP before it makes a token ("Invalid IAM host 10.0.1.10. The IAM host must be a valid RDS or Aurora endpoint."), and_open_connection_taskcatches the error without a log, so the monitor never reads the status again. Both monitors now setIAM_HOSTto the host name they connect for, as the JDBC wrapper'sBlueGreenStatusMonitordoes. The sync monitors kept their connections in the runs below, so the sync path is reached only when a status connection drops afterPREPARATION. Live since9a1a4d9c(feat: add support for blue/green deployments #911, 2025-07-25) in sync andecc898e8(feat: asyncio support (async wrapper, plugins, and SQLAlchemy dialects) #1257, 2026-07-29) inaio/.test_switchovernow starts its probes on the phase the plugin publishes, read from the storage service every 20 ms. An execute on a blue connection opened earlier and a new connect to a green instance, both started inIN_PROGRESS, must return within 60 s (twice the defaultbg_connect_timeout_ms, the bound chore: assert B/G plugin releases suspended traffic promptly aws-advanced-jdbc-wrapper#2098 uses) and use at most 1.0 s of their thread's CPU, and a returned execute must have been held until the phase leftIN_PROGRESS. The first connection to the blue endpoint that opens inPOSTmust reach a server recorded on a green instance before the switchover (MySQL@@hostname, PostgreSQLinet_server_addr(), as JDBC's test reads them) through a driver host that isn't the dialled name, so a wrapper that never substitutes fails whatever the DNS timing.4bb55cfd(chore: add timeout to tests and print stacktrace #1062, 2025-12-19) put a 600 s pytest timeout on every test it couldn't finish. It now waits for the switchover, at most 240 s from the request, then for the RDS API to reportSWITCHOVER_COMPLETEDorSWITCHOVER_FAILED, and assertsSWITCHOVER_COMPLETED. Every thread is a daemon, the main thread waits at most 20 s on the finish latch for them to stop, both tests carry a 900 spytest.mark.timeoutand the plugin's logger stays atINFOwhile any test thread is alive, because a suspended call on an unfixed wrapper logs two debug records per loop pass.autocommit=True, because under MySQL's REPEATABLE READ each poll repeated its first snapshot and the test never saw the switchover complete. Both tests build the services container on the main thread before any thread starts, because conftest releases it before each test and its lazy initialisation takes no lock. The "Green node changed name after SWITCHOVER_COMPLETED." assert is removed, because certificates can still change after the status shows completed (Fix: Blue/Green Deployment Integration Tests aws-advanced-jdbc-wrapper#1705), and the IAM rename check now also matches PostgreSQL's "pam authentication failed".test_switchover_asyncunwrapped the syncBlueGreenPlugin, whichAsyncBlueGreenPlugindoesn't subclass, so its monitors failed with "Unable to find blue/green plugin" on every run, and each worker rancleanup_async()when it ended, releasing services the others still used. It now unwrapsAsyncBlueGreenPluginand runscleanup_async()once, on the main thread, when the test ends. Its probe is an execute on the blue cluster endpoint through the connection that owns the status provider, with the sync execute's 60 s and held checks and no CPU check, because the event loop's CPU includes both status monitors.TestEnvironment.deleteBlueGreenDeploymentread the deployment once and chose the Aurora cluster to delete from that read, so a teardown that started during a switchover took the not-completed branch even when the switchover finished meanwhile. A failed switchover waited 15 minutes and threw, and a deployment that disappeared during the wait threw aNullPointerException.AuroraTestUtility.waitUntilBlueGreenDeploymentSettlednow acceptsavailable,switchover_completed,switchover_failedorinvalid_configuration(as in fix: handle failed blue green provisioning aws-advanced-jdbc-wrapper#2218) and treats a deployment that is gone as settled, and teardown re-reads the deployment after it. Both came in with9a1a4d9c(feat: add support for blue/green deployments #911).AuroraTestUtility.getAuroraParameterGroupFamilyreturnedaurora-postgresql16for every PostgreSQL version, so RDS refused the cluster on the harness's default aurora-postgresql 17.9 ("Please use a Parameter Group with DBParameterGroupFamily aurora-postgresql17"). It now asks RDS (describeDBEngineVersions) for the family, as the JDBC harness does, and falls back toaurora-postgresql<major>.test-bgd-mysql-aurora-sync,test-bgd-mysql-aurora-async,test-bgd-pg-aurora-syncandtest-bgd-pg-aurora-async, each build one 2-instance Aurora environment on Python 3.12 and run one switchover test, because a deployment switches over once. IAM stays on, so the wrapper connects withbg,iam; the MySQL tasks exclude telemetry as the other MySQL tasks do. A new Blue/Green Integration Tests workflow,blue_green_integration_tests.yml, runs them as a matrix withmax-parallel: 2andtimeout-minutes: 120on the Integration Tests workflow's triggers (pushes tomainandworkflow_dispatch), and setsMYSQL_VERSIONandPG_VERSION, the names the harness reads. It is a workflow of its own, as in the JDBC wrapper, sointegration_tests.ymldoesn't change; JDBC runs its Blue/Green tests nightly instead of on pushes tomain.Behaviour changes
bgandiam,federated_authorokta, a status monitor's connection by IP now uses the host name as its IAM host, so the plugin keeps reading the switchover status afterPREPARATION. No property, message or log text changes.mainthat starts the Integration Tests workflow now also starts the Blue/Green Integration Tests workflow, which builds four Blue/Green deployments, two at a time.Not in scope
_open_connection_taskstill catches a failed connect without a log, in both trees, and a user-setiam_hostis still replaced by the host name, as in JDBC.aio/,AsyncBlueGreenStatusMonitor._init_host_list_providercalls the zero-argumentget_async_host_list_provider_supplierwith two arguments, and theTypeErrormakes the monitor close its connection on every pass. With IAM those reconnects now succeed, so the async monitor opens a new connection on each 100 ms pass fromPREPARATIONtoPOST(from reading the code; not measured).AsyncAwsWrapperConnectionkeeps its own status store, and only the connection that created the status provider sees the phases, so the async test has no connect or routing probe.test-bgd-mysql-auroraandtest-bgd-pg-auroratasks still run both tests on one deployment and on every Python version.Tests
The two new unit tests, one per tree, run
_open_connection_taskwithuse_ip_addressset and check thatforce_connectgets the IP as the host and the host name asIAM_HOST. They fail onmainon theIAM_HOSTassertion and pass with this change.pytest tests/unit -Werrorpasses 2656 tests on Python 3.12, with flake8, isort and mypy clean, and the harness compiles with--release 8. The new Gradle tasks ran on real Aurora Blue/Green deployments from a laptop, Python 3.12, IAM on, one deployment per run of about an hour. With this change all four passed. With the product code before #1360 (fdce8d9), both sync tasks failed with oneAssertionErrorlisting "The execute started in IN_PROGRESS didn't return within 60 s.", "The connect started in IN_PROGRESS didn't return within 60 s." and "A connection opened in POST went to the dialled host, not a substitute (...)". Withmain's product code, both async tasks failed with "The plugin phase IN_PROGRESS was never seen, so the execute probe didn't run.", having seen onlyCREATEDandPREPARATION. With this change the sync execute was held fromIN_PROGRESSintoPOSTfor 5.65 s on Aurora MySQL and 3.19 s on Aurora PostgreSQL, using 0.010 s and 0.006 s of CPU, and the async execute for 6.0 s and 3.1 s; each held execute then ended with a connection error from the driver ("Lost connection to MySQL server during query", "SSL error: unexpected eof while reading"), which the checks accept. No run hit a pytest timeout.federated_auth,okta, the RDS Multi-AZ instance tasks and Python versions other than 3.12 weren't run with the switchover tests. Before the job moved to its own workflow, the Integration Tests workflow at13d75b19(run 44704715027) passed all 20 jobs: 8 LTS, 8 Latest and the 4 Blue/Green jobs. At03ff3504the Blue/Green Integration Tests workflow passed its 4 jobs (run 45490801907), each of which ran its one switchover test (1 passed) in about an hour. GitHub can't dispatch a workflow that isn't onmainyet, so that run came from a temporary branch whose one extra commit added the branch to the push trigger. No CHANGELOG entry, message key or docs change.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.