Skip to content

test: assert blue/green switchover calls resume and are routed - #1370

Merged
JuanLeee merged 5 commits into
mainfrom
test/bg-1352-integration
Nov 30, 2026
Merged

JuanLeee merged 5 commits into
mainfrom
test/bg-1352-integration

Conversation

@JuanLeee

@JuanLeee JuanLeee commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

With bg and 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 at PREPARATION: calls aren't held in IN_PROGRESS and new connections aren't sent to the green host in POST. The asyncio monitor reconnects on every pass, so every async switchover with IAM hits it. The switchover integration tests on main couldn'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_switchover and test_switchover_async check 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.

  1. From PREPARATION through POST the status monitors reconnect by IP, and BlueGreenStatusMonitor._open_connection_task and its aio/ twin set IAM_HOST to that IP. IamAuthUtils.get_iam_host rejects 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_task catches the error without a log, so the monitor never reads the status again. Both monitors now set IAM_HOST to the host name they connect for, as the JDBC wrapper's BlueGreenStatusMonitor does. The sync monitors kept their connections in the runs below, so the sync path is reached only when a status connection drops after PREPARATION. Live since 9a1a4d9c (feat: add support for blue/green deployments #911, 2025-07-25) in sync and ecc898e8 (feat: asyncio support (async wrapper, plugins, and SQLAlchemy dialects) #1257, 2026-07-29) in aio/.
  2. test_switchover now 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 in IN_PROGRESS, must return within 60 s (twice the default bg_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 left IN_PROGRESS. The first connection to the blue endpoint that opens in POST must reach a server recorded on a green instance before the switchover (MySQL @@hostname, PostgreSQL inet_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.
  3. The old test waited up to 6 minutes on its finish latch and then slept 12, so since 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 report SWITCHOVER_COMPLETED or SWITCHOVER_FAILED, and asserts SWITCHOVER_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 s pytest.mark.timeout and the plugin's logger stays at INFO while any test thread is alive, because a suspended call on an unfixed wrapper logs two debug records per loop pass.
  4. The direct topology monitors now connect with 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".
  5. test_switchover_async unwrapped the sync BlueGreenPlugin, which AsyncBlueGreenPlugin doesn't subclass, so its monitors failed with "Unable to find blue/green plugin" on every run, and each worker ran cleanup_async() when it ended, releasing services the others still used. It now unwraps AsyncBlueGreenPlugin and runs cleanup_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.
  6. TestEnvironment.deleteBlueGreenDeployment read 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 a NullPointerException. AuroraTestUtility.waitUntilBlueGreenDeploymentSettled now accepts available, switchover_completed, switchover_failed or invalid_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 with 9a1a4d9c (feat: add support for blue/green deployments #911).
  7. AuroraTestUtility.getAuroraParameterGroupFamily returned aurora-postgresql16 for 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 to aurora-postgresql<major>.
  8. Four Gradle tasks, test-bgd-mysql-aurora-sync, test-bgd-mysql-aurora-async, test-bgd-pg-aurora-sync and test-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 with bg,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 with max-parallel: 2 and timeout-minutes: 120 on the Integration Tests workflow's triggers (pushes to main and workflow_dispatch), and sets MYSQL_VERSION and PG_VERSION, the names the harness reads. It is a workflow of its own, as in the JDBC wrapper, so integration_tests.yml doesn't change; JDBC runs its Blue/Green tests nightly instead of on pushes to main.

Behaviour changes

  1. With bg and iam, federated_auth or okta, a status monitor's connection by IP now uses the host name as its IAM host, so the plugin keeps reading the switchover status after PREPARATION. No property, message or log text changes.
  2. Every push to main that 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

  1. _open_connection_task still catches a failed connect without a log, in both trees, and a user-set iam_host is still replaced by the host name, as in JDBC.
  2. In aio/, AsyncBlueGreenStatusMonitor._init_host_list_provider calls the zero-argument get_async_host_list_provider_supplier with two arguments, and the TypeError makes 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 from PREPARATION to POST (from reading the code; not measured).
  3. Each AsyncAwsWrapperConnection keeps 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.
  4. The services container's lazy initialisation still takes no lock; item 4 works around it.
  5. The old test-bgd-mysql-aurora and test-bgd-pg-aurora tasks still run both tests on one deployment and on every Python version.

Tests

The two new unit tests, one per tree, run _open_connection_task with use_ip_address set and check that force_connect gets the IP as the host and the host name as IAM_HOST. They fail on main on the IAM_HOST assertion and pass with this change. pytest tests/unit -Werror passes 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 one AssertionError listing "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 (...)". With main'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 only CREATED and PREPARATION. With this change the sync execute was held from IN_PROGRESS into POST for 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 at 13d75b19 (run 44704715027) passed all 20 jobs: 8 LTS, 8 Latest and the 4 Blue/Green jobs. At 03ff3504 the 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 on main yet, 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.

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.
@JuanLeee
JuanLeee marked this pull request as ready for review November 20, 2026 18:11
Comment thread .github/workflows/integration_tests.yml Outdated
path: ./tests/integration/container/reports
retention-days: 5

blue-green-integration-tests:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep this as a separate workflow?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@JuanLeee
JuanLeee merged commit ae4f35f into main Nov 30, 2026
9 checks passed
@JuanLeee
JuanLeee deleted the test/bg-1352-integration branch November 30, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants