Skip to content

test: isolate shared cloud resources to prevent concurrent CI flakes - #4608

Open
lqiu96 wants to merge 5 commits into
mainfrom
fix-ci-concurrent-test-isolation
Open

test: isolate shared cloud resources to prevent concurrent CI flakes#4608
lqiu96 wants to merge 5 commits into
mainfrom
fix-ci-concurrent-test-isolation

Conversation

@lqiu96

@lqiu96 lqiu96 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

This PR resolves concurrent test collisions and flakiness across parallel matrix runners and simultaneous CI runs by ensuring all integration tests use isolated or idempotent cloud resources:

  1. Pub/Sub Reactive Sample (spring-cloud-gcp-pubsub-reactive-sample):

    • Made topic and subscription names configurable via sample.topic and sample.subscription.
    • Updated MessageSenderController.publish() to await all publishing futures before redirecting, guaranteeing that messages are published before the test checks for them.
    • Configured ReactiveReceiverApplicationIntegrationTest with @DynamicPropertySource using unique UUID-suffixed topic/subscription names, and manage creation/teardown via PubSubAdmin in @BeforeAll / @AfterAll.
  2. Datastore Samples (datastore-basic, datastore, multi-sample):

    • Added application-test.properties for spring-cloud-gcp-data-datastore-basic-sample and wired it via @TestPropertySource on DatastoreBookshelfExampleIntegrationTests.
    • Updated test namespaces to include ${random.uuid} (spring-demo-${java.specification.version}-${random.uuid}) across spring-cloud-gcp-data-datastore-sample, spring-cloud-gcp-data-multi-sample, and spring-cloud-gcp-data-datastore-basic-sample. This prevents concurrent CI runs across different PRs on the same Java version from mutating or deleting each other's test data.
  3. Cloud SQL & AlloyDB Samples (sql-postgres, sql-postgres-r2dbc, alloydb, sql-mysql):

    • Changed schema.sql to use CREATE TABLE IF NOT EXISTS users and data.sql to use non-conflicting inserts (ON CONFLICT (email) DO NOTHING for Postgres/AlloyDB; INSERT IGNORE for MySQL).
    • Removed destructive @AfterEach DROP TABLE IF EXISTS users from AlloyDbSampleApplicationIntegrationTests, SqlPostgresSampleApplicationIntegrationTests, and SqlMysqlSampleApplicationIntegrationTests, and made cleanup.sql in the R2DBC sample a no-op.
    • Documented in each sample's README.adoc and Java comments that the users table persists after running the sample and instructions for manual cleanup if desired.

@lqiu96
lqiu96 requested a review from a team as a code owner August 28, 2026 04:34
@lqiu96
lqiu96 force-pushed the fix-ci-concurrent-test-isolation branch from 27d1981 to 1d8743f Compare August 28, 2026 04:38
- Pub/Sub Reactive sample:
  - Make topic and subscription configurable via sample.topic and sample.subscription.
  - Await publishing futures in MessageSenderController.publish() to guarantee messages are enqueued before responding.
  - Dynamically generate unique topic and subscription names per test in ReactiveReceiverApplicationIntegrationTest and manage their lifecycle via PubSubAdmin.
- Datastore samples:
  - Add application-test.properties with a unique random UUID namespace for spring-cloud-gcp-data-datastore-basic-sample and bind via @TestPropertySource.
  - Include ${random.uuid} in test namespaces for spring-cloud-gcp-data-datastore-sample and spring-cloud-gcp-data-multi-sample to prevent cross-PR / cross-runner collision.
- Cloud SQL & AlloyDB samples:
  - Make table creation idempotent with CREATE TABLE IF NOT EXISTS users in schema.sql.
  - Make initial row insertion idempotent (ON CONFLICT (email) DO NOTHING for Postgres/AlloyDB, INSERT IGNORE for MySQL).
  - Remove destructive @AfterEach DROP TABLE calls and cleanup.sql table drops that break concurrent test runners sharing database instances.
  - Document table persistence and manual cleanup instructions in each sample's README.adoc.
@lqiu96
lqiu96 force-pushed the fix-ci-concurrent-test-isolation branch from 1d8743f to fad35e8 Compare August 28, 2026 04:45
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.

1 participant