Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed May 31, 2024
1 parent 56a6c6c commit 1e3a6eb
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 16 deletions.
5 changes: 1 addition & 4 deletions core-tests/src/coroutine/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ TEST(coroutine_system, flock) {
ASSERT_EQ(swoole_random_bytes(buf->str, buf->size - 1), buf->size - 1);
buf->str[buf->size - 1] = 0;

swoole_event_init(SW_EVENTLOOP_WAIT_EXIT);

Coroutine::create([&buf](void *) {
test::coroutine::run([&buf](void *) {
int fd = swoole_coroutine_open(test_file, File::WRITE | File::CREATE, 0666);
ASSERT_TRUE(fd > 0);
swoole_coroutine_flock_ex(test_file, fd, LOCK_EX);
Expand All @@ -77,7 +75,6 @@ TEST(coroutine_system, flock) {
swoole_coroutine_close(fd);
});

swoole_event_wait();
unlink(test_file);
}

Expand Down
11 changes: 8 additions & 3 deletions tests/include/lib/src/ProcessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,19 @@ public function kill(bool $force = false)
}
}

public function initFreePorts(int $num = 1)
/**
* @param int $num
* @param int $increment Only used for constant port number, must be a constant
* @return void
*/
public function initFreePorts(int $num = 1, int $increment = 0): void
{
for ($i = $num; $i--;) {
$this->freePorts[] = $this->useConstantPorts ? (9500 + $num - $i + count($this->freePorts)) : get_one_free_port();
$this->freePorts[] = $this->useConstantPorts ? (9500 + $num - $i + count($this->freePorts) + $increment) : get_one_free_port();
}
}

public function initFreeIPv6Ports(int $num = 1)
public function initFreeIPv6Ports(int $num = 1): void
{
for ($i = $num; $i--;) {
$this->freePorts[] = $this->useConstantPorts ? (9500 + $num - $i + count($this->freePorts)) : get_one_free_port_ipv6();
Expand Down
8 changes: 4 additions & 4 deletions tests/swoole_event/add_after_server_start.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require __DIR__ . '/../include/bootstrap.php';

use Swoole\Server;

const FILE = __DIR__.'/tmp_result.txt';
const FILE = __DIR__ . '/tmp_result.txt';

$pm = new SwooleTest\ProcessManager;
$pm->parentFunc = function ($pid) use ($pm) {
Expand All @@ -22,12 +22,12 @@ $pm->parentFunc = function ($pid) use ($pm) {
$pm->childFunc = function () use ($pm) {
$serv = new Server('127.0.0.1', $pm->getFreePort(), SWOOLE_PROCESS);
$serv->set(array(
"worker_num" => 1,
'worker_num' => 1,
'log_file' => '/dev/null',
));
$serv->on("start", function (Server $serv) use ($pm) {
$fp = stream_socket_client("tcp://www.qq.com:80", $errno, $errstr, 30);
fwrite($fp, "GET / HTTP/1.1\r\nHost: www.qq.com\r\n\r\n");
$fp = stream_socket_client("tcp://" . TEST_DOMAIN_2 . ":80", $errno, $errstr, 30);
fwrite($fp, "GET / HTTP/1.1\r\nHost: " . TEST_DOMAIN_2 . "\r\n\r\n");

Swoole\Event::add($fp, function ($fp) use ($pm) {
$resp = fread($fp, 8192);
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/co-stream.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Swoole\Thread;
use Swoole\Thread\Queue;

$tm = new \SwooleTest\ThreadManager();
$tm->initFreePorts();
$tm->initFreePorts(increment: crc32(__FILE__) % 1000);

$tm->parentFunc = function () use ($tm) {
Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/server/base.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use Swoole\Thread\Lock;
const SIZE = 2 * 1024 * 1024;

$tm = new \SwooleTest\ThreadManager();
$tm->initFreePorts();
$tm->initFreePorts(increment: crc32(__FILE__) % 1000);

$tm->parentFunc = function () use ($tm) {
$queue = new Swoole\Thread\Queue();
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/server/send_large_packet.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use Swoole\Thread\Lock;
const SIZE = 2 * 1024 * 1024;

$tm = new \SwooleTest\ThreadManager();
$tm->initFreePorts();
$tm->initFreePorts(increment: crc32(__FILE__) % 1000);

$tm->parentFunc = function () use ($tm) {
$queue = new Swoole\Thread\Queue();
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/stream.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Swoole\Thread;
use Swoole\Thread\Queue;

$tm = new \SwooleTest\ThreadManager();
$tm->initFreePorts();
$tm->initFreePorts(increment: crc32(__FILE__) % 1000);

$tm->parentFunc = function () use ($tm) {
$queue = new Queue();
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/stream_arg.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Swoole\Thread;
use Swoole\Thread\Queue;

$tm = new \SwooleTest\ThreadManager();
$tm->initFreePorts();
$tm->initFreePorts(increment: crc32(__FILE__) % 1000);

$tm->parentFunc = function () use ($tm) {
$fp = stream_socket_server('tcp://127.0.0.1:' . $tm->getFreePort(), $errno, $errstr);
Expand Down

0 comments on commit 1e3a6eb

Please sign in to comment.