Skip to content

Commit 1e3a6eb

Browse files
committed
Fix tests
1 parent 56a6c6c commit 1e3a6eb

File tree

8 files changed

+18
-16
lines changed

8 files changed

+18
-16
lines changed

core-tests/src/coroutine/system.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ TEST(coroutine_system, flock) {
4949
ASSERT_EQ(swoole_random_bytes(buf->str, buf->size - 1), buf->size - 1);
5050
buf->str[buf->size - 1] = 0;
5151

52-
swoole_event_init(SW_EVENTLOOP_WAIT_EXIT);
53-
54-
Coroutine::create([&buf](void *) {
52+
test::coroutine::run([&buf](void *) {
5553
int fd = swoole_coroutine_open(test_file, File::WRITE | File::CREATE, 0666);
5654
ASSERT_TRUE(fd > 0);
5755
swoole_coroutine_flock_ex(test_file, fd, LOCK_EX);
@@ -77,7 +75,6 @@ TEST(coroutine_system, flock) {
7775
swoole_coroutine_close(fd);
7876
});
7977

80-
swoole_event_wait();
8178
unlink(test_file);
8279
}
8380

tests/include/lib/src/ProcessManager.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,19 @@ public function kill(bool $force = false)
251251
}
252252
}
253253

254-
public function initFreePorts(int $num = 1)
254+
/**
255+
* @param int $num
256+
* @param int $increment Only used for constant port number, must be a constant
257+
* @return void
258+
*/
259+
public function initFreePorts(int $num = 1, int $increment = 0): void
255260
{
256261
for ($i = $num; $i--;) {
257-
$this->freePorts[] = $this->useConstantPorts ? (9500 + $num - $i + count($this->freePorts)) : get_one_free_port();
262+
$this->freePorts[] = $this->useConstantPorts ? (9500 + $num - $i + count($this->freePorts) + $increment) : get_one_free_port();
258263
}
259264
}
260265

261-
public function initFreeIPv6Ports(int $num = 1)
266+
public function initFreeIPv6Ports(int $num = 1): void
262267
{
263268
for ($i = $num; $i--;) {
264269
$this->freePorts[] = $this->useConstantPorts ? (9500 + $num - $i + count($this->freePorts)) : get_one_free_port_ipv6();

tests/swoole_event/add_after_server_start.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require __DIR__ . '/../include/bootstrap.php';
1010

1111
use Swoole\Server;
1212

13-
const FILE = __DIR__.'/tmp_result.txt';
13+
const FILE = __DIR__ . '/tmp_result.txt';
1414

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

3232
Swoole\Event::add($fp, function ($fp) use ($pm) {
3333
$resp = fread($fp, 8192);

tests/swoole_thread/co-stream.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use Swoole\Thread;
1414
use Swoole\Thread\Queue;
1515

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

1919
$tm->parentFunc = function () use ($tm) {
2020
Runtime::enableCoroutine(SWOOLE_HOOK_ALL);

tests/swoole_thread/server/base.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use Swoole\Thread\Lock;
1515
const SIZE = 2 * 1024 * 1024;
1616

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

2020
$tm->parentFunc = function () use ($tm) {
2121
$queue = new Swoole\Thread\Queue();

tests/swoole_thread/server/send_large_packet.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use Swoole\Thread\Lock;
1515
const SIZE = 2 * 1024 * 1024;
1616

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

2020
$tm->parentFunc = function () use ($tm) {
2121
$queue = new Swoole\Thread\Queue();

tests/swoole_thread/stream.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use Swoole\Thread;
1313
use Swoole\Thread\Queue;
1414

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

1818
$tm->parentFunc = function () use ($tm) {
1919
$queue = new Queue();

tests/swoole_thread/stream_arg.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use Swoole\Thread;
1313
use Swoole\Thread\Queue;
1414

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

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

0 commit comments

Comments
 (0)