|
| 1 | +--TEST-- |
| 2 | +swoole_table: force unlock |
| 3 | +--SKIPIF-- |
| 4 | +<?php require __DIR__ . '/../include/skipif.inc'; ?> |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | +require __DIR__ . '/../include/bootstrap.php'; |
| 8 | + |
| 9 | +use Swoole\Process; |
| 10 | + |
| 11 | +ini_set('memory_limit', '16M'); |
| 12 | + |
| 13 | +$table = new \Swoole\Table(1); |
| 14 | +$table->column('string', \Swoole\Table::TYPE_STRING, 4 * 1024 * 1024); |
| 15 | +$table->column('int', \Swoole\Table::TYPE_INT, 8); |
| 16 | +$table->create(); |
| 17 | +$str_size = 4 * 1024 * 1024; |
| 18 | +$str_value = random_bytes($str_size); |
| 19 | +$data = [ |
| 20 | + 'string' => $str_value, |
| 21 | + 'int' => PHP_INT_MAX |
| 22 | +]; |
| 23 | +$table->set('test', $data); |
| 24 | + |
| 25 | +(new Process(function () use ($table) { |
| 26 | + $str = str_repeat('A', 4 * 1024 * 1024); |
| 27 | + // Fatal error: memory exhausted |
| 28 | + $data = $table->get('test'); |
| 29 | + var_dump(strlen($data['string'])); |
| 30 | + var_dump(strlen($str)); |
| 31 | + var_dump(memory_get_usage()); |
| 32 | +}))->start(); |
| 33 | + |
| 34 | +Process::wait(); |
| 35 | + |
| 36 | +$data = $table->get('test'); |
| 37 | +Assert::eq(strlen($data['string']), $str_size); |
| 38 | +Assert::eq($data['string'], $str_value); |
| 39 | +echo "Done\n"; |
| 40 | +?> |
| 41 | +--EXPECTF-- |
| 42 | +Fatal error: Allowed memory size of %d bytes exhausted at %s (tried to allocate %d bytes) in %s on line %d |
| 43 | +[%s] WARNING lock: lock process[%d] not exists, force unlock |
| 44 | +Done |
0 commit comments