Skip to content

fix: PostgreSQL unit test hang#1083

Merged
hsinn0 merged 1 commit intomainfrom
postgres_test_hang
Apr 8, 2026
Merged

fix: PostgreSQL unit test hang#1083
hsinn0 merged 1 commit intomainfrom
postgres_test_hang

Conversation

@hsinn0
Copy link
Copy Markdown
Contributor

@hsinn0 hsinn0 commented Apr 6, 2026

  • Added FlywayPostgresTestStripConcurrentlyConfiguration to transform SQL scripts and remove CONCURRENTLY keyword from index DDL to prevent blocking during parallel test execution.
  • Updated ParallelPostgresTestDataSourceConfiguration to use HikariCP with connection pool limits so as to avoid too many connection errors. Also set the timeouts to avoid indefinite waits.
  • Also updated ParallelPostgresTestDataSourceConfiguration to use non-pooled database connection for 'create database'.
  • AI-Assisted.

- Added FlywayPostgresTestStripConcurrentlyConfiguration to transform SQL scripts and remove CONCURRENTLY keyword from index DDL to prevent blocking during parallel test execution.
- Updated ParallelPostgresTestDataSourceConfiguration to use HikariCP with connection pool limits so as to avoid too many connection errors. Also set the timeouts to avoid indefinite waits.
- Also updated ParallelPostgresTestDataSourceConfiguration to use non-pooled database connection for 'create database'.
Comment on lines +18 to +23
* For unit tests against PostgreSQL, strip `CONCURRENTLY` from index DDL in Flyway SQL migrations so
* migrations do not block on other connections (e.g. Flyway bookkeeping). Production migrations are
* unchanged on disk; only the in-memory script content is transformed.
*
* Every `*.sql` resource is wrapped (Flyway relative paths omit `db/migration/postgres/`); replacements are
* no-ops for scripts that do not use concurrent index DDL.
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.

question: curious why this needed now, is it due to changes in Flyway or recent changes to the tests?

Is this related to flyway/flyway#3508 or flyway/flyway#3682
workaround suggests applying config flyway.postgresql.transactional.lock=false

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.

Copy link
Copy Markdown
Contributor Author

@hsinn0 hsinn0 Apr 8, 2026

Choose a reason for hiding this comment

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

question: curious why this needed now, is it due to changes in Flyway or recent changes to the tests?

The unit-tests-postgres-* jobs in Coucourse have been failing frequently with timeouts in the past, too. It seems that the timeout is just more frequent (or consistent) these days. I've never bothered looked into those CI timeouts, thinking they are flakes, as rerunning usually made the jobs pass.
For the matter of local run in my dev box, I do not regularly run the tests against postgresql database unless there is something postgresql-specific that need to be looked into. So no idea when the problem started to occur there. It is possible that this was caused by some changes in other dependencies such as hikari pool or hibernate.

Is this related to flyway/flyway#3508 or flyway/flyway#3682 workaround suggests applying config flyway.postgresql.transactional.lock=false

Not sure if our current issue is related to those old flyway issues. Sounds similar, though. And yes, we are already setting transitionalLock to false (in FlywayMigrationStrategyTestConfig for tests).

As the goal is to prevent the hang for the tests and the issue is not to be expected to occur in production, and the change only affect test run with postgresql database, I think that just removing concurrently from the create/drop index statements for test only is the way to go.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, the latest issue: flyway/flyway#3961
Seems like there's no other solutions yet.

@hsinn0 hsinn0 requested a review from dlinsley April 8, 2026 19:09
Copy link
Copy Markdown
Contributor

@dlinsley dlinsley left a comment

Choose a reason for hiding this comment

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

I was able to locally observe the PostgreSQL unit test hang locally. These changes do resolve the observed hang during tests allowing them to complete locally. Thanks for addressing the questions!

@github-project-automation github-project-automation bot moved this from Inbox to Pending Merge | Prioritized in Foundational Infrastructure Working Group Apr 8, 2026
@hsinn0 hsinn0 merged commit fc37bbb into main Apr 8, 2026
2 checks passed
@hsinn0 hsinn0 deleted the postgres_test_hang branch April 8, 2026 21:56
@github-project-automation github-project-automation bot moved this from Pending Merge | Prioritized to Done in Foundational Infrastructure Working Group Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants