Skip to content

ext/dba/tests/dba_gdbm.phpt: test failure due to key ordering #14786

Closed

Description

@orlitzky

Description

Original report: https://bugs.gentoo.org/935379

The diff for this failed tests contains e.g.

-key4: Another Content String
 key2: Content String 2
 key5: The last content string
-[key10]name10: Content String 10
 name9: Content String 9
+[key10]name10: Content String 10
+key4: Another Content String
 [key30]name30: Content String 30
 Total keys: 6

The corresponding test code is,

// Fetch data                                                               
$key = dba_firstkey($db_writer);
$total_keys = 0;
while ($key) {
    echo $key, ': ', dba_fetch($key, $db_writer), \PHP_EOL;
    $key = dba_nextkey($db_writer);
    $total_keys++;
}
echo 'Total keys: ', $total_keys, \PHP_EOL;

So to me it looks like the insert order is not guaranteed to be the iteration order according to dba_firstkey() and dba_nextkey(). Since there are only six keys, I guess we could sort the output (in a locale-independent way) before printing it?

PHP Version

PHP-8.2.20

Operating System

Gentoo Linux

Activity

  1. Girgias commented on Jul 3, 2024

    @Girgias
    Member

    This might actually something that changed in the GDBM driver/lib? As I don't see why it would change randomly, I had consistent behaviour when I was actively refactoring this a while back

  2. orlitzky commented on Jul 3, 2024

    @orlitzky
    ContributorAuthor

    It's possible but my first guess would be that it's on x86. The same version with the same build flags passes for me on amd64.

  3. orlitzky commented on Jul 4, 2024

    @orlitzky
    ContributorAuthor

    The iteration order is apparently based on gdbm's internal hashes and FWIW gdbm's own test suite sorts the output, see e.g. https://git.savannah.gnu.org/cgit/gdbm.git/tree/tests/create00.at

    The gtdump utility is a little CLI program that uses firstkey() and nextkey().

  4. Girgias commented on Jul 6, 2024

    @Girgias
    Member

    Right, then adding a sort and referencing the upstream test makes sense.

  5. added a commit that references this issue on Jul 15, 2024
    36a3054
  6. added a commit that references this issue on Jul 26, 2024
    44b0baf
  7. added a commit that references this issue on Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions