Skip to content

test(Database): fix state leaks and random-order test determinism for MySQLi, PostgreSQL, and OCI8 - #10581

Open
gr8man wants to merge 7 commits into
codeigniter4:developfrom
gr8man:fix-postgres-tests
Open

gr8man wants to merge 7 commits into
codeigniter4:developfrom
gr8man:fix-postgres-tests

Conversation

@gr8man

@gr8man gr8man commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Description
Fixes database tests to be deterministic under random execution order
for MySQLi, PostgreSQL, and OCI8 drivers. Ref: #9968
Ref: #9968
Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@carson-codeigniter4 carson-codeigniter4 Bot added github_actions Pull requests that update Github_actions code needs template Opened issues not following the bug form template labels Sep 23, 2026
@carson-codeigniter4

Copy link
Copy Markdown

Hi there, @gr8man! 👋

It looks like this pull request does not follow our template:

Please update the description to follow the template. The needs template label will be removed automatically once it does.

@carson-codeigniter4 carson-codeigniter4 Bot removed the needs template Opened issues not following the bug form template label Sep 23, 2026
@gr8man
gr8man force-pushed the fix-postgres-tests branch 2 times, most recently from 7b7132e to 36e3579 Compare September 25, 2026 23:30
@gr8man
gr8man marked this pull request as draft September 26, 2026 19:43
@gr8man
gr8man marked this pull request as ready for review September 26, 2026 21:03
@gr8man

gr8man commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

Hey everyone! 👋

I've finished testing and cleaning up the branch. I stripped out all the unnecessary changes (especially the OCI8 experiments and non-essential tweaks in system/).

What remains now is (hopefully!) the bare minimum strictly required to make the database test suite deterministic and green under --order-by=random:

  • Per-component database schema isolation in Registrar (to prevent parallel jobs from stepping on each other)
  • Dropping team_members and migrations_lock during teardowns to avoid state leaks
  • Ensuring custom connection instances in tests don't pollute the shared registry ($getShared = false)
  • A deterministic index selection preference (PRIMARY over UNIQUE) for PostgreSQL upsert()
  • Minor dynamic database name adjustments in tests (UpsertTest, ExecuteLogMessageFormatTest)

All checks are green across the board now. The PR is ready for review! 🚀

Copilot AI left a comment

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.

Copilot review overview

🟡 Changes recommended

Unresolved cleanup, CI coverage, identifier quoting, assertion, and regression-test issues remain.

Review effort: Lite
Findings: 1 Medium severity · 2 Low severity

Open (3)
What changed in this PR

This PR improves database test isolation and random-order determinism across supported drivers, while stabilizing PostgreSQL upsert constraint selection.

Changes:

  • Adds per-component database and connection cleanup.
  • Improves migration, table, and metadata state handling.
  • Updates PostgreSQL upsert behavior and randomized-test CI configuration.
File Summary
tests/​system/​Database/​Migrations/​MigrationRunnerTest.php Cleans migration locks; lock handling must prevent leaked migration state.
tests/​system/​Database/​Live/​UpsertTest.php Updates database-aware expectations; add primary-versus-unique constraint regression coverage.
tests/​system/​Database/​Live/​Postgre/​ConnectTest.php Uses isolated PostgreSQL connections.
tests/​system/​Database/​Live/​MySQLi/​NumberNativeTest.php Isolates MySQLi connection settings.
tests/​system/​Database/​Live/​MySQLi/​FoundRowsTest.php Isolates MySQLi connection state.
tests/​system/​Database/​Live/​MetadataTest.php Resets metadata state and restores prefixes.
tests/​system/​Database/​Live/​GetVersionTest.php Adjusts version validation; malformed trailing values must remain rejected.
tests/​system/​Database/​Live/​ForgeTest.php Adds cleanup; dependent tables must be dropped before parent tables.
tests/​system/​Database/​Live/​ExecuteLogMessageFormatTest.php Handles varied backtrace formats.
tests/​system/​Database/​Live/​ConnectTest.php Resets shared connection state.
tests/​_support/​Database/​Migrations/​20160428212500_Create_test_tables.php Improves migration cleanup.
tests/​_support/​Config/​Registrar.php Creates isolated databases; MySQL identifiers need safe quoting.
system/​Database/​Postgre/​Builder.php Prefers primary constraints for upserts.
.github/​workflows/​test-random-execution.yml Updates database CI setup; OCI8 coverage needs a verification path.
.github/​scripts/​random-tests-config.txt Enables Database random testing.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/_support/Config/Registrar.php Outdated
(int) $dbParams['port'],
);
if (! $conn->connect_error) {
$conn->query('CREATE DATABASE IF NOT EXISTS ' . $conn->real_escape_string($dbParams['database']));
Comment on lines +472 to +475
$uniqueIndexes = array_filter($tableIndexes, static function ($index) use ($fieldNames): bool {
$hasAllFields = count(array_intersect($index->fields, $fieldNames)) === count($index->fields);

return ($index->type === 'UNIQUE' || $index->type === 'PRIMARY') && $hasAllFields;
return $index->type === 'PRIMARY' && $hasAllFields;
$version = $this->db->getVersion();

$this->assertMatchesRegularExpression('/\A\d+(\.\d+)*\z/', $version);
$this->assertMatchesRegularExpression('/\A\d+(\.\d+)*/', $version);
… MySQLi, PostgreSQL, and OCI8

Fixes database tests to be deterministic under random execution order
for MySQLi, PostgreSQL, and OCI8 drivers. Ref codeigniter4#9968.

- Fix random-order test execution issues and state leakage under
  PostgreSQL, MySQL, and OCI8
- Isolate per-component database schemas for parallel random-test runs
- Safely extract dbParams keys with null coalescing in Registrar
- Drop team_members table in migration down method
- Run Oracle components sequentially and exclude Oracle from the random
  test matrix (single shared schema via DSN causes ORA-00955 collisions)
- Handle case-insensitive cached tableExists and catalog lookups in OCI8
- Fix OCI8 insertID() to preserve quoted table name case so Oracle
  USER_TAB_COLUMNS lookups match forge-created (lowercase) tables
@gr8man
gr8man force-pushed the fix-postgres-tests branch from 4fc3f9b to af7d2b3 Compare October 10, 2026 13:00

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

github_actions Pull requests that update Github_actions code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants