Skip to content

Commit b881c8f

Browse files
committed
修复测试
1 parent 5469667 commit b881c8f

1 file changed

Lines changed: 47 additions & 1 deletion

File tree

‎tests/bootstrap.php‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,26 @@ function testEnv($name, $default = null)
115115
echo 'Stoping Http2 server...', \PHP_EOL;
116116
echo `{$cmd}`, \PHP_EOL;
117117
echo 'Http2 Server stoped!', \PHP_EOL;
118+
119+
$pidFile = __DIR__ . '/server/WebSocket/wss-server.pid';
120+
if (is_file($pidFile))
121+
{
122+
$pid = (int) file_get_contents($pidFile);
123+
if ($pid > 0)
124+
{
125+
echo 'Stoping WSS server (PID: ' . $pid . ')...', \PHP_EOL;
126+
if (function_exists('posix_kill'))
127+
{
128+
posix_kill($pid, \SIGTERM);
129+
}
130+
else
131+
{
132+
`kill -15 {$pid} 2>/dev/null`;
133+
}
134+
}
135+
@unlink($pidFile);
136+
echo 'WSS Server stoped!', \PHP_EOL;
137+
}
118138
}
119139
}
120140

@@ -246,7 +266,7 @@ function waitForWebSocketServer($port)
246266
for ($i = 0; $i < 10; ++$i)
247267
{
248268
@file_get_contents(str_replace('ws://', 'http://', testEnv('WS_SERVER_HOST', 'ws://127.0.0.1:8900/')));
249-
if (isset($http_response_header[0]) && 'HTTP/1.1 400 Bad Request' === $http_response_header[0])
269+
if (isset($http_response_header[0]) && false !== stripos($http_response_header[0], '400 Bad Request'))
250270
{
251271
$serverStarted = true;
252272
break;
@@ -285,5 +305,31 @@ function waitForWebSocketServer($port)
285305
{
286306
throw new \RuntimeException('Http2 server start failed');
287307
}
308+
309+
// WSS Server (Swoole SSL WebSocket)
310+
$wssPidFile = __DIR__ . '/server/WebSocket/wss-server.pid';
311+
$cmd = 'nohup /usr/bin/env php "' . __DIR__ . '/server/WebSocket/wss-server.php" > "' . __DIR__ . '/server/WebSocket/wss-server.log" 2>&1 & echo $! > "' . $wssPidFile . '"';
312+
echo 'Starting WSS server...', \PHP_EOL;
313+
echo `{$cmd}`, \PHP_EOL;
314+
$serverStarted = false;
315+
for ($i = 0; $i < 10; ++$i)
316+
{
317+
$context = stream_context_create(['ssl' => ['verify_peer' => false, 'verify_peer_name' => false]]);
318+
@file_get_contents('https://127.0.0.1:8902/', false, $context);
319+
if (isset($http_response_header[0]) && false !== stripos($http_response_header[0], '400'))
320+
{
321+
$serverStarted = true;
322+
break;
323+
}
324+
sleep(1);
325+
}
326+
if ($serverStarted)
327+
{
328+
echo 'WSS server started!', \PHP_EOL;
329+
}
330+
else
331+
{
332+
throw new \RuntimeException('WSS server start failed');
333+
}
288334
}
289335
}

0 commit comments

Comments
 (0)