Skip to content

Commit

Permalink
Pipeline adjustments.6
Browse files Browse the repository at this point in the history
  • Loading branch information
lotharthesavior committed Sep 30, 2024
1 parent e27eadb commit 292f1ca
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 34 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ jobs:
shell: bash
run: |
cd /var/www/jacked-server
sudo vendor/bin/phpunit
# sudo -u www-data -- vendor/bin/phpunit
sudo -u www-data -- vendor/bin/phpunit
13 changes: 6 additions & 7 deletions tests/Feature/HttpServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use JackedPhp\JackedServer\Helpers\Config;
use OpenSwoole\Coroutine;
use OpenSwoole\Coroutine\Http\Client as CoroutineHttpClient;
use OpenSwoole\Process;
use Tests\TestCase;

class HttpServerTest extends TestCase
Expand All @@ -14,7 +13,7 @@ public function test_can_get_base_input()
{
$configFile = ROOT_DIR . '/config/jacked-server-http.php';

$serverPid = $this->startServer(configFile: $configFile);
$this->startServer(configFile: $configFile);
$status = null;
$outcome = '';

Expand All @@ -32,15 +31,15 @@ public function test_can_get_base_input()
);
$this->assertEquals(200, $status);

Process::kill($serverPid, SIGKILL);
self::tearServerDown();
sleep(3);
}

public function test_can_send_post()
{
$configFile = ROOT_DIR . '/config/jacked-server-http.php';

$serverPid = $this->startServer(configFile: $configFile);
$this->startServer(configFile: $configFile);
$status = null;
$outcome = '';
$expectedData = json_encode(['data' => 'test']);
Expand All @@ -64,15 +63,15 @@ public function test_can_send_post()
);
$this->assertEquals(200, $status);

Process::kill($serverPid, SIGKILL);
self::tearServerDown();
sleep(3);
}

public function test_can_send_form()
{
$configFile = ROOT_DIR . '/config/jacked-server-http.php';

$serverPid = $this->startServer(configFile: $configFile);
$this->startServer(configFile: $configFile);
$status = null;
$outcome = '';
$expectedData = ['data' => 'test'];
Expand All @@ -96,7 +95,7 @@ public function test_can_send_form()
);
$this->assertEquals(200, $status);

Process::kill($serverPid, SIGKILL);
self::tearServerDown();
sleep(3);
}
}
3 changes: 2 additions & 1 deletion tests/Feature/Traits/ServerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public static function tearServerDown(): void
{
$processName = 'jacked-server-process';
$command = "ps aux | grep '$processName' | grep -v grep | awk '{print $2}' | xargs -I {} kill -9 {}";
Coroutine::run(fn() => System::exec($command));

Coroutine::run(fn() => System::exec($command, get_error_stream: true));

$output2 = self::getServerProcesses();
if (!empty($output2)) {
Expand Down
37 changes: 13 additions & 24 deletions tests/Feature/WsServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Tests\Feature;

use Error;
use Exception;
use JackedPhp\JackedServer\Helpers\Config;
use OpenSwoole\Atomic;
use OpenSwoole\Coroutine;
Expand All @@ -12,25 +10,9 @@
use Tests\TestCase;
use Kanata\ConveyorServerClient\Client;
use Throwable;
use WebSocket\ConnectionException;

class WsServerTest extends TestCase
{
/** @var array<int> */
protected array $processesPids;

/**
* @after
* @return void
*/
public function stopProcesses(): void
{
foreach ($this->processesPids as $pid) {
Process::kill($pid, SIGKILL);
}
sleep(3);
}

protected function startWsClient(
string $configFile,
?callable $onReadyCallback = null,
Expand Down Expand Up @@ -76,7 +58,7 @@ protected function startWsClient(
redirectStdIO: true,
enableCoroutine: false,
);
$this->processesPids[] = $process->start();
$process->start();

if (null !== $processTimeout) {
$process->setTimeout($processTimeout);
Expand Down Expand Up @@ -113,7 +95,7 @@ public function test_can_broadcast_message()
$configFile = ROOT_DIR . '/config/jacked-server.php';

// @throws Exception
$this->processesPids[] = $this->startServer(configFile: $configFile);
$this->startServer(configFile: $configFile);

$atomic = new Atomic();

Expand Down Expand Up @@ -147,14 +129,17 @@ public function test_can_broadcast_message()
usleep(300000); // 0.3 sec

$this->assertEquals('Message received: Test Message 1', $result);

self::tearServerDown();
sleep(3);
}

public function test_can_authenticate_remote_server_at_handshake(): void
{
$configFile = ROOT_DIR . '/ws-auth/jacked-server-with-ws-auth.php';

// @throws Exception
$this->processesPids[] = $this->startServer(configFile: $configFile);
$this->startServer(configFile: $configFile);

$token1 = $this->getToken($configFile);
$token2 = $this->getToken($configFile);
Expand Down Expand Up @@ -194,16 +179,17 @@ public function test_can_authenticate_remote_server_at_handshake(): void
usleep(300000); // 0.3 sec

$this->assertEquals('Message received: Test Message 1', $result);

self::tearServerDown();
sleep(3);
}

public function test_fail_to_authenticate_remote_server_at_handshake(): void
{
$configFile = ROOT_DIR . '/ws-auth/jacked-server-with-ws-auth-2.php';

// @throws Exception
$this->processesPids[] = $this->startServer(
configFile: $configFile,
);
$this->startServer(configFile: $configFile);

$process = $this->startWsClient(
onReadyCallback: function ($client, $worker) {
Expand All @@ -230,5 +216,8 @@ public function test_fail_to_authenticate_remote_server_at_handshake(): void
needle: '403',
haystack: $parsedResult['rawMessage'],
);

self::tearServerDown();
sleep(3);
}
}

0 comments on commit 292f1ca

Please sign in to comment.