Skip to content

ci: fix flaky prepared statements test#1026

Merged
meskill merged 2 commits into
mainfrom
push-xnlwnowurxsn
Jun 2, 2026
Merged

ci: fix flaky prepared statements test#1026
meskill merged 2 commits into
mainfrom
push-xnlwnowurxsn

Conversation

@meskill
Copy link
Copy Markdown
Contributor

@meskill meskill commented May 30, 2026

fixes #1006

Improve reliability of prepared statement test by following this structure for testing inside the transaction pooling mode:

  1. Prepare statement on some backend connection from pool
  2. Pin the used connection with fake transaction so it can't be reused by other clients while transaction is alive. It'll be the same transaction since the pooled connection are reused in LIFO mode
  3. Start multiple parallel connections that just picking some connections from pool and changing it's order
  4. Test multiple times if the initial prepared statement works as expected depending on the configuration

These tests should basically verify the behavior of the prepared_statement options and to do this we need to use different backend connection to verify pgdog properly proxies these calls. There is no mechanism to control it from the client so the test might look clunky but the intention is to test multiple pool connection that they behave as expected when different clients use prepared statements

@blacksmith-sh

This comment has been minimized.

@meskill meskill force-pushed the push-xnlwnowurxsn branch 5 times, most recently from f419239 to c3e0166 Compare June 1, 2026 15:20
@blacksmith-sh

This comment has been minimized.

@meskill meskill changed the title ci: fix flaky tests ci: fix some flaky tests Jun 1, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@meskill meskill marked this pull request as ready for review June 1, 2026 15:56
Copy link
Copy Markdown
Contributor

@sgrif sgrif left a comment

Choose a reason for hiding this comment

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

Would like to see more context given about why these changes make the tests less flaky. For the Ruby tests in particular it seems like this pretty fundamentally changes what they're testing, instead of testing the same thing in a more reproducible manner. If we're okay with that change it'd be nice to have more context as to why we're okay with that.

Comment thread integration/copy_data/setup.sql Outdated
'notifications', (random() > 0.5)
) AS settings
FROM generate_series(1, 10000) AS gs(id);
FROM generate_series(1, 100000) AS gs(id);
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.

It's not clear from the commit context why increasing the users by 10x makes this test less flaky. Can you add that to the commit message?

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.

moved to another pr #1028

ensure
conn.close rescue nil
end
conn = connect
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.

This seems like it pretty fundamentally changes the semantics of the test. Do we not care about the behavior of multiple competing threads? Can you clarify why we don't care in your commit message or PR description?

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.

I've changed the tests and the pr description to address this and other comments related to prepared statements, hope this helps

mutex.synchronize { errors << e.message }
ensure
conn.close rescue nil
conn = connect
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.

Same issue as the previous comment here. Can you clarify why we no longer care about the behavior with multiple competing threads?

mutex.synchronize { errors << e.message }
ensure
conn.close rescue nil
conn = connect
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.

Same thing here

@meskill meskill force-pushed the push-xnlwnowurxsn branch from c3e0166 to bf71845 Compare June 2, 2026 08:47
@meskill meskill marked this pull request as draft June 2, 2026 11:19
@meskill meskill force-pushed the push-xnlwnowurxsn branch from 82a72f7 to 5b499a4 Compare June 2, 2026 12:04
meskill added 2 commits June 2, 2026 15:23
Use pinned transaction instead of flaky multithreaded query execution to
test the behaviour of prepared_transaction option and make sure the test
request is landing on the another backend connection that hadn't
prepared the transaction.
Instead of relying on a single query after preparing statement for the
verification use combined approach that more reliably verifies the
expected behaviour.

- hold one connection with prepared_statement to verify how other pool
  connections are affected
- run multiple parallel connection to randomize the actually used pool
  connection and do not rely on LIFO ordering for fetching backend
  connections from pool
@meskill meskill force-pushed the push-xnlwnowurxsn branch from 5b499a4 to a23a714 Compare June 2, 2026 16:12
@meskill meskill changed the title ci: fix some flaky tests ci: fix prepared statements test Jun 2, 2026
@meskill meskill changed the title ci: fix prepared statements test ci: fix flaky prepared statements test Jun 2, 2026
@meskill meskill requested a review from sgrif June 2, 2026 16:25
@meskill meskill marked this pull request as ready for review June 2, 2026 16:25
Copy link
Copy Markdown
Collaborator

@levkk levkk left a comment

Choose a reason for hiding this comment

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

Testing a negative is hard for sure. Good job!

Copy link
Copy Markdown
Contributor

@sgrif sgrif left a comment

Choose a reason for hiding this comment

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

ty 💜

@meskill meskill merged commit 75335fb into main Jun 2, 2026
24 checks passed
@meskill meskill deleted the push-xnlwnowurxsn branch June 2, 2026 20:20
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.

test: flaky Ruby test

3 participants