Skip to content

Commit 1892e3a

Browse files
committed
Fix brittle shmop test
To solve bug #70886, the test uses random keys to prevent collisions; however, this is not guaranteed, and as such it may even collide with other tests in the shmop test suite. The proper solution would be to use a single key (which could be randomly generated), but to actually `shmop_close()` after each `shmop_delete()`. This would, however, not work on Windows due to bug #65987. Therefore we use three different keys for now.
1 parent 129fd64 commit 1892e3a

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

ext/shmop/tests/002.phpt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,34 @@ edgarsandi - <edgar.r.sandi@gmail.com>
1313
?>
1414
--FILE--
1515
<?php
16-
$hex_shm_id = function(){
17-
return mt_rand(1338, 9999);
18-
};
1916

2017
echo PHP_EOL, '## shmop_open function tests ##';
2118
// warning outputs: 4 parameters expected
2219
var_dump($shm_id = shmop_open());
2320

2421
// warning outputs: invalid flag when the flags length != 1
25-
var_dump(shmop_open($hex_shm_id(), '', 0644, 1024));
22+
var_dump(shmop_open(1338, '', 0644, 1024));
2623

2724
// warning outputs: invalid access mode
28-
var_dump(shmop_open($hex_shm_id(), 'b', 0644, 1024));
25+
var_dump(shmop_open(1338, 'b', 0644, 1024));
2926

3027
// warning outputs: unable to attach or create shared memory segment
3128
var_dump(shmop_open(null, 'a', 0644, 1024));
3229

3330
// warning outputs: Shared memory segment size must be greater than zero
34-
var_dump(shmop_open($hex_shm_id(), "c", 0666, 0));
31+
var_dump(shmop_open(1338, "c", 0666, 0));
3532

3633
echo PHP_EOL, '## shmop_read function tests ##';
3734
// warning outputs: 3 parameters expected
3835
var_dump(shmop_read());
3936

4037
// warning outputs: start is out of range
41-
$shm_id = shmop_open($hex_shm_id(), 'n', 0600, 1024);
38+
$shm_id = shmop_open(1338, 'n', 0600, 1024);
4239
var_dump(shmop_read($shm_id, -10, 0));
4340
shmop_delete($shm_id);
4441

4542
// warning outputs: count is out of range
46-
$shm_id = shmop_open($hex_shm_id(), 'n', 0600, 1024);
43+
$shm_id = shmop_open(1339, 'n', 0600, 1024);
4744
var_dump(shmop_read($shm_id, 0, -10));
4845
shmop_delete($shm_id);
4946

@@ -52,7 +49,7 @@ echo PHP_EOL, '## shmop_write function tests ##';
5249
var_dump(shmop_write());
5350

5451
// warning outputs: offset out of range
55-
$shm_id = shmop_open($hex_shm_id(), 'n', 0600, 1024);
52+
$shm_id = shmop_open(1340, 'n', 0600, 1024);
5653
var_dump(shmop_write($shm_id, 'text to try write', -10));
5754
shmop_delete($shm_id);
5855

0 commit comments

Comments
 (0)