Skip to content

Commit 44b0baf

Browse files
authored
ext/dba/tests: sort expected test output (php#14962)
* ext/dba/tests/setup/setup_dba_tests.inc: sort test output Iterating through a database with firstkey() and nextkey() is guaranteed to retrieve all rows, but apparently not in any particular order. This is causing a test failure for at least one user, so we steal the sort() approach from GDBM to ensure that the output is predictable. * ext/dba/tests/dba_*.phpt: sort expected test output The actual output is now sorted for consistency, so we need to update the expected output as well. As a nice side effect, some differences in the expected outputs for the various engines have been eliminated. Closes phpGH-14786 * ext/pgsql/tests/80_bug14383.phpt: sort expected test output This test uses a routine from ext/dba that now sorts its (actual) output, so we have to sort the expected output here as well. * ext/dba/tests/setup/setup_dba_tests.inc: update comment After doing some more digging, it looks like GDBM isn't the only engine where the iteration order with firstkey() and nextkey() might change unexpectedly.
1 parent ab449a7 commit 44b0baf

File tree

8 files changed

+43
-28
lines changed

8 files changed

+43
-28
lines changed

ext/dba/tests/dba_flatfile.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ bool(true)
2929
bool(true)
3030
Try to remove key 1 again
3131
bool(false)
32+
[key10]name10: Content String 10
33+
[key30]name30: Content String 30
3234
key2: Content String 2
3335
key4: Another Content String
3436
key5: The last content string
3537
name9: Content String 9
36-
[key10]name10: Content String 10
37-
[key30]name30: Content String 30
3838
Total keys: 6
3939
Key 1 exists? N
4040
Key 2 exists? Y

ext/dba/tests/dba_gdbm.phpt

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ bool(true)
3535
bool(true)
3636
Try to remove key 1 again
3737
bool(false)
38-
key4: Another Content String
38+
[key10]name10: Content String 10
39+
[key30]name30: Content String 30
3940
key2: Content String 2
41+
key4: Another Content String
4042
key5: The last content string
41-
[key10]name10: Content String 10
4243
name9: Content String 9
43-
[key30]name30: Content String 30
4444
Total keys: 6
4545
Key 1 exists? N
4646
Key 2 exists? Y
@@ -81,12 +81,12 @@ bool(true)
8181
bool(true)
8282
Try to remove key 1 again
8383
bool(false)
84-
key4: Another Content String
84+
[key10]name10: Content String 10
85+
[key30]name30: Content String 30
8586
key2: Content String 2
87+
key4: Another Content String
8688
key5: The last content string
87-
[key10]name10: Content String 10
8889
name9: Content String 9
89-
[key30]name30: Content String 30
9090
Total keys: 6
9191
Key 1 exists? N
9292
Key 2 exists? Y

ext/dba/tests/dba_inifile.phpt

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ bool(true)
3030
bool(true)
3131
Try to remove key 1 again
3232
bool(false)
33-
key2: Content String 2
34-
key4: Another Content String
35-
key5: The last content string
36-
name9: Content String 9
3733
[key10]:
3834
[key10]name10: Content String 10
3935
[key30]:
4036
[key30]name30: Content String 30
37+
key2: Content String 2
38+
key4: Another Content String
39+
key5: The last content string
40+
name9: Content String 9
4141
Total keys: 8
4242
Key 1 exists? N
4343
Key 2 exists? Y

ext/dba/tests/dba_ndbm.phpt

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ bool(true)
3636
bool(true)
3737
Try to remove key 1 again
3838
bool(false)
39-
key4: Another Content String
39+
[key10]name10: Content String 10
40+
[key30]name30: Content String 30
4041
key2: Content String 2
42+
key4: Another Content String
4143
key5: The last content string
42-
[key10]name10: Content String 10
4344
name9: Content String 9
44-
[key30]name30: Content String 30
4545
Total keys: 6
4646
Key 1 exists? N
4747
Key 2 exists? Y
@@ -82,12 +82,12 @@ bool(true)
8282
bool(true)
8383
Try to remove key 1 again
8484
bool(false)
85-
key4: Another Content String
85+
[key10]name10: Content String 10
86+
[key30]name30: Content String 30
8687
key2: Content String 2
88+
key4: Another Content String
8789
key5: The last content string
88-
[key10]name10: Content String 10
8990
name9: Content String 9
90-
[key30]name30: Content String 30
9191
Total keys: 6
9292
Key 1 exists? N
9393
Key 2 exists? Y

ext/dba/tests/dba_qdbm.phpt

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ bool(true)
3535
bool(true)
3636
Try to remove key 1 again
3737
bool(false)
38+
[key10]name10: Content String 10
39+
[key30]name30: Content String 30
3840
key2: Content String 2
3941
key4: Another Content String
4042
key5: The last content string
4143
name9: Content String 9
42-
[key10]name10: Content String 10
43-
[key30]name30: Content String 30
4444
Total keys: 6
4545
Key 1 exists? N
4646
Key 2 exists? Y
@@ -81,12 +81,12 @@ bool(true)
8181
bool(true)
8282
Try to remove key 1 again
8383
bool(false)
84+
[key10]name10: Content String 10
85+
[key30]name30: Content String 30
8486
key2: Content String 2
8587
key4: Another Content String
8688
key5: The last content string
8789
name9: Content String 9
88-
[key10]name10: Content String 10
89-
[key30]name30: Content String 30
9090
Total keys: 6
9191
Key 1 exists? N
9292
Key 2 exists? Y

ext/dba/tests/dba_tcadb.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ bool(true)
3030
bool(true)
3131
Try to remove key 1 again
3232
bool(false)
33+
[key10]name10: Content String 10
34+
[key30]name30: Content String 30
3335
key2: Content String 2
3436
key4: Another Content String
3537
key5: The last content string
3638
name9: Content String 9
37-
[key10]name10: Content String 10
38-
[key30]name30: Content String 30
3939
Total keys: 6
4040
Key 1 exists? N
4141
Key 2 exists? Y

ext/dba/tests/setup/setup_dba_tests.inc

+17-2
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,29 @@ function run_standard_tests_ex(string $handler, string $name, LockFlag $lock, bo
102102
echo 'Try to remove key 1 again', \PHP_EOL;
103103
var_dump(dba_delete("key1", $db_writer));
104104

105-
// Fetch data
105+
// Fetch and sort data. We sort to guarantee that the output is
106+
// consistent across invocations and architectures. When iterating
107+
// with firstkey() and nextkey(), several engines (GDBM, LMDB,
108+
// QDBM) make no promise about the iteration order. Others (TCADB,
109+
// DBM) explicitly state that the order is arbitrary. With GDBM at
110+
// least, the order appears platform-dependent -- we have a report
111+
// in Github issue 14786. GDBM's own test suite sorts this output,
112+
// suggesting that sorting is a reasonable workaround for the issue.
113+
$output = [];
114+
106115
$key = dba_firstkey($db_writer);
107116
$total_keys = 0;
108117
while ($key) {
109-
echo $key, ': ', dba_fetch($key, $db_writer), \PHP_EOL;
118+
$output[] = $key . ': ' . dba_fetch($key, $db_writer) . \PHP_EOL;
110119
$key = dba_nextkey($db_writer);
111120
$total_keys++;
112121
}
122+
123+
sort($output, SORT_STRING);
124+
foreach ($output as $line) {
125+
echo $line;
126+
}
127+
113128
echo 'Total keys: ', $total_keys, \PHP_EOL;
114129
for ($i = 1; $i < 6; $i++) {
115130
echo "Key $i exists? ", dba_exists("key$i", $db_writer) ? 'Y' : 'N', \PHP_EOL;

ext/pgsql/tests/80_bug14383.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ bool(true)
3939
bool(true)
4040
Try to remove key 1 again
4141
bool(false)
42+
[key10]name10: Content String 10
43+
[key30]name30: Content String 30
4244
key2: Content String 2
4345
key4: Another Content String
4446
key5: The last content string
4547
name9: Content String 9
46-
[key10]name10: Content String 10
47-
[key30]name30: Content String 30
4848
Total keys: 6
4949
Key 1 exists? N
5050
Key 2 exists? Y

0 commit comments

Comments
 (0)