Skip to content

Avoid temp table name collisions in parallel tests - #6614

Closed
roji wants to merge 1 commit into
npgsql:mainfrom
roji:roji-fix-flaky-test
Closed

roji wants to merge 1 commit into
npgsql:mainfrom
roji:roji-fix-flaky-test

Conversation

@roji

@roji roji commented Jun 28, 2026 •

Copy link
Copy Markdown
Member

Fixes a flaky failure exposed when dotnet test runs multiple test assemblies against the same PostgreSQL database concurrently. Each test project now runs against its own PG database.

Copilot AI review requested due to automatic review settings June 28, 2026 14:34
@roji
roji requested a review from vonzshik as a code owner June 28, 2026 14:34
@roji
roji force-pushed the roji-fix-flaky-test branch from a7d7dbc to 218e824 Compare June 28, 2026 14:35
@roji roji changed the title Run CI setup steps in parallel Avoid temp table name collisions in parallel tests Jun 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to reduce CI wall-clock time by overlapping PostgreSQL setup with .NET build steps, and fixes a concurrency-related test flake by making generated temp table names unique across multiple testhost processes.

Changes:

  • Added a centralized GenerateTempTableName() helper that includes the current process ID to prevent temp table name collisions under concurrent test execution.
  • Updated transaction test helpers to use GenerateTempTableName() instead of directly incrementing _tempTableCounter.
  • Modified the GitHub Actions build workflow to attempt running PostgreSQL setup “in parallel” with other setup/build steps and to run tests with --no-build.
Show a summary per file
File Description
test/Npgsql.Tests/TestUtil.cs Introduces GenerateTempTableName() using Environment.ProcessId + counter and switches temp table creation helpers to use it.
test/Npgsql.Tests/SystemTransactionTests.cs Updates temp table helper to call GenerateTempTableName() and removes now-unused System.Threading import.
test/Npgsql.Tests/DistributedTransactionTests.cs Updates temp table helper to call GenerateTempTableName() to avoid cross-process name collisions.
.github/workflows/build.yml Reorders CI steps and introduces background: true / wait-all: true to attempt parallelizing PostgreSQL setup; switches test invocation to --no-build.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Low

Copilot AI review requested due to automatic review settings June 28, 2026 14:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment thread test/Npgsql.Tests/TestUtil.cs Resolved
@roji roji closed this Jun 29, 2026
@roji roji reopened this Jul 8, 2026
Copilot AI review requested due to automatic review settings July 8, 2026 08:33
@roji
roji force-pushed the roji-fix-flaky-test branch from 218e824 to a90ca0b Compare July 8, 2026 08:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 12/12 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment thread test/Npgsql.Tests/TestUtil.cs Resolved
Comment thread test/Shared/TestDatabase.cs Resolved
@roji
roji enabled auto-merge (squash) July 8, 2026 08:47
@roji
roji force-pushed the roji-fix-flaky-test branch from a90ca0b to 88e7550 Compare July 8, 2026 09:20
Comment thread test/Npgsql.Tests/TestUtil.cs Resolved
Comment thread test/Npgsql.Tests/TestUtil.cs Resolved
Copilot AI review requested due to automatic review settings July 8, 2026 13:11
@roji
roji force-pushed the roji-fix-flaky-test branch from 88e7550 to 589c3b1 Compare July 8, 2026 13:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 12/12 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment thread test/Shared/TestDatabase.cs Resolved
Copilot AI review requested due to automatic review settings July 9, 2026 12:28
@roji
roji force-pushed the roji-fix-flaky-test branch from 589c3b1 to 2d76ee2 Compare July 9, 2026 12:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 12/12 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment thread test/Shared/TestDatabase.cs Resolved
Copilot AI review requested due to automatic review settings July 12, 2026 12:16
@roji
roji force-pushed the roji-fix-flaky-test branch from 2d76ee2 to f2435ca Compare July 12, 2026 12:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 12/12 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment thread test/Shared/TestDatabase.cs Resolved
Comment thread test/Npgsql.Tests/TestUtil.cs Resolved
Copilot AI review requested due to automatic review settings July 12, 2026 12:28
@roji
roji force-pushed the roji-fix-flaky-test branch from f2435ca to 86408aa Compare July 12, 2026 12:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 13/13 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment thread test/Npgsql.Tests/Support/TestBase.cs Resolved
Copilot AI review requested due to automatic review settings July 12, 2026 12:34
@roji
roji force-pushed the roji-fix-flaky-test branch from 86408aa to b1b386d Compare July 12, 2026 12:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review details

Comments suppressed due to low confidence (1)

test/Npgsql.Tests/Support/TestBase.cs:814

  • Database creation uses string concatenation ("CREATE DATABASE " + conn.Database) without quoting/escaping the database identifier. This can fail for valid database names requiring quoting (e.g. mixed-case, dashes) and also allows SQL injection if the database name comes from an environment-provided connection string. Consider quoting the identifier the same way TestDatabase.EnsureTestDatabase does.
                    var builder = new NpgsqlConnectionStringBuilder(conn.ConnectionString)
                    {
                        Pooling = false,
                        Database = "postgres"
                    };
  • Files reviewed: 13/13 changed files
  • Comments generated: 0 new
  • Review effort level: Low

Copilot AI review requested due to automatic review settings July 12, 2026 12:40
@roji
roji force-pushed the roji-fix-flaky-test branch from b1b386d to c424881 Compare July 12, 2026 12:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 13/13 changed files
  • Comments generated: 0 new
  • Review effort level: Low

@roji roji closed this Jul 13, 2026
auto-merge was automatically disabled July 13, 2026 10:17

Pull request was closed

@roji

roji commented Jul 13, 2026

Copy link
Copy Markdown
Member Author

Went with the alternate approach in #6621

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.

3 participants