mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-10-31 11:03:22 +01:00
On the test MAIN, moving the HTTP port to 8081 (held by another service) was saved and announced to the nodes, while nginx's reload failed to bind it and kept running on 8080. The save of this machine's own row now checks each port it does not use yet (ServerService::portsTaken: a connect to 127.0.0.1) and answers STATUS_PORT_IN_USE (49) with a message on the server form. Other servers' rows are not checked: their ports are on another machine.
34 lines
1.5 KiB
PHP
34 lines
1.5 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use XcVm\Domain\Server\ServerService;
|
|
|
|
/**
|
|
* A server's save refuses a new port another program already holds on this
|
|
* machine: nginx's reload would fail to bind it and keep the old one, while
|
|
* the row and the nodes' announcement named the new one.
|
|
*/
|
|
final class ServerPortsTakenTest extends TestCase {
|
|
private const ROW = ['http_broadcast_port' => 8080, 'http_ports_add' => '8090,8091', 'https_broadcast_port' => 8443, 'https_ports_add' => null, 'rtmp_port' => 8880];
|
|
|
|
public function testOnlyANewPortSomethingHoldsIsTaken(): void {
|
|
$rHeld = [8080, 8081, 8443, 8880, 8090];
|
|
$rListening = static fn(int $rPort): bool => in_array($rPort, $rHeld, true);
|
|
$this->assertSame([], ServerService::portsTaken(self::ROW, [8080, 8443, 8880, 8090], $rListening), 'the row\'s own ports are this nginx\'s');
|
|
$this->assertSame([8081], ServerService::portsTaken(self::ROW, [8081, 8443, 8880], $rListening), 'held by another program');
|
|
$this->assertSame([], ServerService::portsTaken(self::ROW, [8082, '8443', 'x', 0], $rListening), 'free, or not a port');
|
|
}
|
|
|
|
public function testItAsksTheMachineByDefault(): void {
|
|
$rServer = stream_socket_server('tcp://127.0.0.1:0');
|
|
$this->assertNotFalse($rServer);
|
|
$rPort = (int) substr(strrchr((string) stream_socket_get_name($rServer, false), ':'), 1);
|
|
try {
|
|
$this->assertSame([$rPort], ServerService::portsTaken(self::ROW, [$rPort]));
|
|
} finally {
|
|
fclose($rServer);
|
|
}
|
|
$this->assertSame([], ServerService::portsTaken(self::ROW, [$rPort]), 'free once closed');
|
|
}
|
|
}
|