Skip to content

Commit

Permalink
add thread test
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Apr 15, 2024
1 parent d3eae1d commit a538cbc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/include/skipif.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ skip(
(function () {
global $argv;
skip_if_php_version_lower_than('7.0');
if (defined('SWOOLE_THREAD')) {
$targs = Swoole\Thread::getArguments();
if ($targs) {
$argv = $targs[0];
}
}
if (!getenv('PHPT') && substr($argv[0], -4) === '.php') {
skip('please read ' . dirname(dirname(__FILE__)) . '/README.md and try again');
}
Expand Down
35 changes: 35 additions & 0 deletions tests/swoole_thread/lock.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
swoole_thread: lock
--SKIPIF--
<?php
require __DIR__ . '/../include/skipif.inc';
?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

use Swoole\Thread;
use Swoole\Lock;

$args = Thread::getArguments();

if (empty($args)) {
global $argv;
$lock = new Lock;
$lock->lock();
$thread = Thread::exec(__FILE__, $argv, $lock);
$lock->lock();
echo "main thread\n";
$thread->join();
} else {
echo "child thread\n";
$lock = $args[1];
usleep(200_000);
$lock->unlock();
exit(0);
}
?>
--EXPECTF--
child thread
main thread

0 comments on commit a538cbc

Please sign in to comment.