Skip to content

Commit

Permalink
Update autobahn tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Feb 4, 2019
1 parent 572fad6 commit db024db
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .php_cs.dist
Expand Up @@ -5,7 +5,8 @@ $config = new Amp\CodeStyle\Config;
$config->getFinder()
->in(__DIR__ . '/examples')
->in(__DIR__ . '/src')
->in(__DIR__ . '/test');
->in(__DIR__ . '/test')
->in(__DIR__ . '/test-autobahn');

$cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__;

Expand Down
9 changes: 3 additions & 6 deletions .travis.yml
Expand Up @@ -6,7 +6,6 @@ services:
- docker

php:
- 7.0
- 7.1
- 7.2
- 7.3
Expand All @@ -21,11 +20,9 @@ env:
- AMP_DEBUG=true

before_install:
- docker pull php:7.1
- docker pull php:7.3
- docker pull crossbario/autobahn-testsuite
- if [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then
phpenv config-rm xdebug.ini || echo "No xdebug config.";
fi
- phpenv config-rm xdebug.ini || echo "No xdebug config.";

install:
- composer update -n --prefer-dist
Expand All @@ -35,7 +32,7 @@ install:
script:
- phpdbg -qrr vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml
- PHP_CS_FIXER_IGNORE_ENV=1 php vendor/bin/php-cs-fixer --diff --dry-run -v fix
- docker run -d --rm -v ${PWD}:/app --net="host" --name aerys php:7.1 php /app/test-autobahn/server.php
- docker run -d --rm -v ${PWD}:/app --net="host" --name amp-websocket php:7.3 php /app/test-autobahn/server.php
- docker run -ti --rm -v ${PWD}/test-autobahn/config:/config -v ${PWD}/test-autobahn/reports:/reports --net="host" --name fuzzingclient crossbario/autobahn-testsuite wstest -m fuzzingclient -s config/fuzzingclient.json
- php test-autobahn/report.php

Expand Down
8 changes: 4 additions & 4 deletions test-autobahn/report.php
@@ -1,18 +1,18 @@
<?php

require dirname(__DIR__) . "/vendor/autoload.php";
require \dirname(__DIR__) . "/vendor/autoload.php";

const REPORT_PATH = __DIR__ . "/reports/servers/index.json";

$climate = new League\CLImate\CLImate;

if (!file_exists(REPORT_PATH)) {
if (!\file_exists(REPORT_PATH)) {
$climate->red("Could not find autobahn test results json file");
exit(1);
}

$report = file_get_contents(REPORT_PATH);
$report = json_decode($report, true);
$report = \file_get_contents(REPORT_PATH);
$report = \json_decode($report, true);

if (!isset($report["amphp-websocket-server"])) {
$climate->red("Could not find result set for amphp-websocket-server");
Expand Down
46 changes: 22 additions & 24 deletions test-autobahn/server.php
@@ -1,48 +1,46 @@
<?php

require dirname(__DIR__) . "/vendor/autoload.php";
require \dirname(__DIR__) . "/vendor/autoload.php";

use Amp\Http\Server\Request;
use Amp\Http\Server\Response;
use Amp\Http\Server\Server;
use Amp\Http\Server\Websocket;
use Amp\Socket;
use Amp\Websocket\Client;
use Amp\Websocket\Message;
use Amp\Websocket\Server\Options;
use Amp\Websocket\Server\Websocket;
use Psr\Log\NullLogger;

Amp\Loop::run(function () {
/* --- http://localhost:9001/ ------------------------------------------------------------------- */

$websocket = new class extends Websocket\Websocket
{
public function onHandshake(Request $request, Response $response)
{
return $response;
}
$options = (new Options)
->withBytesPerSecondLimit(\PHP_INT_MAX)
->withFrameSizeLimit(\PHP_INT_MAX)
->withFramesPerSecondLimit(\PHP_INT_MAX)
->withMessageSizeLimit(\PHP_INT_MAX)
->withValidateUtf8(true);

public function onOpen(int $clientId, Request $request)
$websocket = new class($options) extends Websocket {
public function onHandshake(Request $request, Response $response): Response
{
return $response;
}

public function onData(int $clientId, Websocket\Message $message)
public function onConnection(Client $client, Request $request): \Generator
{
if ($message->isBinary()) {
yield $this->broadcastBinary(yield $message->buffer());
} else {
yield $this->broadcast(yield $message->buffer());
while ($message = yield $client->receive()) {
\assert($message instanceof Message);
if ($message->isBinary()) {
yield $this->broadcastBinary(yield $message->buffer());
} else {
yield $this->broadcast(yield $message->buffer());
}
}
}

public function onClose(int $clientId, int $code, string $reason)
{
}
};

$websocket->setBytesPerMinuteLimit(PHP_INT_MAX);
$websocket->setFrameSizeLimit(PHP_INT_MAX);
$websocket->setFramesPerSecondLimit(PHP_INT_MAX);
$websocket->setMessageSizeLimit(PHP_INT_MAX);
$websocket->setValidateUtf8(true);

$server = new Server([Socket\listen("127.0.0.1:9001")], $websocket, new NullLogger);
return $server->start();
});

0 comments on commit db024db

Please sign in to comment.