Skip to content

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

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

test(Database): fix state leaks and random-order test determinism for MySQLi, PostgreSQL, and OCI8#10377
gr8man wants to merge 6 commits into
codeigniter4:developfrom
gr8man:fix-postgres-tests

Conversation

@gr8man

@gr8man gr8man commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

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

MySQLi (commits cd8f5dc, 8cc20d3)

  • ConnectTest: use correct host/port for connection assertions.
  • ForgeTest: access addField before usage in testDropTableSuccess.
  • WorkerModeTest: clear history between runs.
  • FoundRowsTest, NumberNativeTest: remove setPrefix() calls that leaked
    prefix state to subsequent tests.

PostgreSQL (commit 24d5a44)

  • ForgeTest::testDropTableSuccess: verify table existence with correct
    table name after creation.
  • ConnectTest: skip charset assertion when not applicable.

OCI8 (commit fc9e325)

  • Connection::initialize() – sets NLS_DATE_FORMAT, NLS_TIMESTAMP_FORMAT,
    and NLS_TIMESTAMP_TZ_FORMAT via ALTER SESSION after connecting.
    Prevents ORA-01843 "invalid month" when NLS env vars are not set.
  • _indexData() – wraps $row->CONSTRAINT_TYPE ?? '' to avoid PHP 8.1+
    deprecation "Using null as an array offset" for indexes without a
    matching constraint.
  • MetadataTest – captures prefix before createExtraneousTable() so the
    original prefix is preserved even if an exception is thrown.
  • ExecuteLogMessageFormatTest – removes stale OCI8-specific array_slice
    that caused a backtrace line pattern mismatch.

All 859 OCI8 database tests pass with 0 failures in both default and
randomised execution order. MySQLi and PostgreSQL tests also pass
deterministically under random order.

gr8man added 5 commits July 4, 2026 23:02
- Connection::initialize() sets NLS session formats via ALTER SESSION,
  preventing ORA-01843 when env vars are not set.
- _indexData() handles null CONSTRAINT_TYPE to avoid deprecated null
  array offset error.
- MetadataTest captures prefix before createExtraneousTable() to prevent
  prefix leak on exception.
- ExecuteLogMessageFormatTest removes stale OCI8-specific array_slice.
@gr8man

gr8man commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

IMPORTANT

Note to reviewers and developers: Please ensure that tests are run regularly with the --order-by=random flag during development. Identifying test pollution and global state leakage bugs at a later stage is extremely difficult and time-consuming, as these failures only manifest under very specific test suite execution orders.

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