Skip to content

Commit

Permalink
[test] fix ci 11
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Apr 15, 2024
1 parent c5e55f6 commit 1fbbd49
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ext-src/swoole_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ struct ZendArray : ThreadResource {

void intkey_offsetGet(zend_long index, zval *return_value) {
lock_.lock_rd();
ArrayItem *item = (ArrayItem *) zend_hash_index_find(&ht, index);
ArrayItem *item = (ArrayItem *) zend_hash_index_find_ptr(&ht, index);
if (item) {
item->fetch(return_value);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ done

# run tests @params($1=list_file, $2=options)
run_tests(){
echo \
./start.sh \
"`tr '\n' ' ' < ${1} | xargs`" \
-w ${1} \
${2}
Expand Down
45 changes: 45 additions & 0 deletions tests/swoole_thread/async-io.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--TEST--
swoole_thread: async-io
--SKIPIF--
<?php
require __DIR__ . '/../include/skipif.inc';
?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

use Swoole\Thread;

const C = 4;
const N = 256;

$args = Thread::getArguments();
$running = true;
$md5 = md5_file(__FILE__);

if (empty($args)) {
$threads = [];
$atomic = new Swoole\Atomic();
for ($i = 0; $i < C; $i++) {
$threads[] = Thread::exec(__FILE__, $argv, $i, $atomic);
}
for ($i = 0; $i < C; $i++) {
$threads[$i]->join();
}
Assert::eq($atomic->get(), C * N);
} else {
$atomic = $args[2];
Co\run(function () use ($atomic, $md5) {
$n = N;
while ($n--) {
$atomic->add();
$rs = \Swoole\Coroutine\System::readFile(__FILE__);
Assert::eq(md5($rs), $md5);
}
});
exit(0);
}
echo "DONE\n";
?>
--EXPECTF--
DONE
62 changes: 62 additions & 0 deletions tests/swoole_thread/queue.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--TEST--
swoole_thread: queue
--SKIPIF--
<?php
require __DIR__ . '/../include/skipif.inc';
?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

use Swoole\Thread;
use Swoole\Thread\Queue;

const C = 4;
const N = 1024;

$args = Thread::getArguments();
$total_parent = 0;
$total_child = 0;

if (empty($args)) {
$threads = [];
$queue = new Queue;
$map = new Thread\Map();
for ($i = 0; $i < C; $i++) {
$threads[] = Thread::exec(__FILE__, $argv, $i, $queue, $map);
}
$n = N;
while ($n--) {
$rdata = base64_encode(random_bytes(random_int(16, 128)));
$total_parent += strlen($rdata);
$queue->push($rdata, Queue::NOTIFY_ONE);
usleep(random_int(100, 1000));
}
$n = 4;
while ($n--) {
$queue->push('', Queue::NOTIFY_ONE);
}
for ($i = 0; $i < C; $i++) {
$threads[$i]->join();
$total_child += $map[$i];
}
Assert::eq($queue->count(), 0);
Assert::eq($total_parent, $total_child);
} else {
$i = $args[1];
$queue = $args[2];
$map = $args[3];
$map[$i] = 0;
while (1) {
$job = $queue->pop(-1);
if (!$job) {
break;
}
$map[$i] += strlen($job);
Assert::assert(strlen($job), 16);
}
exit(0);
}
?>
--EXPECTF--

0 comments on commit 1fbbd49

Please sign in to comment.