Skip to content

Commit ca297e1

Browse files
committed
Run autobahn tests on Travis
1 parent 996b723 commit ca297e1

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
sudo: false
1+
sudo: required
22

33
language: php
44

5+
services:
6+
- docker
7+
58
php:
69
- 7.0
710
- 7.1
@@ -18,6 +21,8 @@ env:
1821

1922
before_install:
2023
- phpenv config-rm xdebug.ini || echo "No xdebug config."
24+
- docker pull crossbario/autobahn-testsuite
25+
- docker run -d -v ${PWD}/test-autobahn/config:/config -v ${PWD}/test-autobahn/reports:/reports -p 9001:9001 --name fuzzingserver crossbario/autobahn-testsuite
2126

2227
install:
2328
- composer update -n --prefer-dist
@@ -30,6 +35,7 @@ install:
3035

3136
script:
3237
- phpdbg -qrr vendor/bin/phpunit --verbose --coverage-php coverage/cov/main.cov
38+
- php test-autobahn/runner.php
3339
- PHP_CS_FIXER_IGNORE_ENV=1 php vendor/bin/php-cs-fixer --diff --dry-run -v fix
3440

3541
after_script:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"url": "ws://127.0.0.1:9001",
3+
"outdir": "./reports/clients",
4+
"cases": ["*"],
5+
"exclude-cases": ["7.*", "12.*", "13.*"],
6+
"exclude-agent-cases": {}
7+
}

test-autobahn/runner.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
use Amp\ByteStream\StreamException;
4+
use Amp\Loop;
5+
use Amp\Websocket;
6+
7+
require __DIR__ . '/../vendor/autoload.php';
8+
9+
const AGENT = 'amphp/websocket';
10+
11+
Loop::run(function () {
12+
$errors = 0;
13+
14+
$options = (new Websocket\Options)
15+
->withMaximumMessageSize(32 * 1024 * 1024)
16+
->withMaximumFrameSize(32 * 1024 * 1024)
17+
->withValidateUtf8(true);
18+
19+
/** @var Websocket\Connection $connection */
20+
$connection = yield Websocket\connect('ws://127.0.0.1:9001/getCaseCount');
21+
/** @var Websocket\Message $message */
22+
$message = yield $connection->receive();
23+
$cases = (int) yield $message->buffer();
24+
25+
echo "Going to run {$cases} test cases." . PHP_EOL;
26+
27+
for ($i = 1; $i < $cases; $i++) {
28+
$connection = yield Websocket\connect('ws://127.0.0.1:9001/getCaseInfo?case=' . $i . '&agent=' . AGENT);
29+
$message = yield $connection->receive();
30+
$info = \json_decode(yield $message->buffer(), true);
31+
32+
print $info['id'] . ' ' . str_repeat('-', 80 - strlen($info['id']) - 1) . PHP_EOL;
33+
print wordwrap($info['description'], 80, PHP_EOL) . ' ';
34+
35+
$connection = yield Websocket\connect('ws://127.0.0.1:9001/runCase?case=' . $i . '&agent=' . AGENT, null, null, $options);
36+
37+
try {
38+
while ($message = yield $connection->receive()) {
39+
$content = yield $message->buffer();
40+
41+
if ($message->isBinary()) {
42+
yield $connection->sendBinary($content);
43+
} else {
44+
yield $connection->send($content);
45+
}
46+
}
47+
} catch (Websocket\ClosedException $e) {
48+
// ignore
49+
} catch (AssertionError $e) {
50+
print 'Assertion error: ' . $e->getMessage() . PHP_EOL;
51+
$connection->close();
52+
} catch (Error $e) {
53+
print 'Error: ' . $e->getMessage() . PHP_EOL;
54+
$connection->close();
55+
} catch (StreamException $e) {
56+
print 'Stream exception: ' . $e->getMessage() . PHP_EOL;
57+
$connection->close();
58+
}
59+
60+
$connection = yield Websocket\connect('ws://127.0.0.1:9001/getCaseStatus?case=' . $i . '&agent=' . AGENT);
61+
$message = yield $connection->receive();
62+
print ($result = \json_decode(yield $message->buffer(), true)['behavior']);
63+
64+
if ($result === 'FAILED') {
65+
$errors++;
66+
}
67+
68+
print PHP_EOL . PHP_EOL;
69+
}
70+
71+
$connection = yield Websocket\connect('ws://127.0.0.1:9001/updateReports?agent=' . AGENT);
72+
$connection->close();
73+
74+
Loop::stop();
75+
76+
if ($errors) {
77+
exit(1);
78+
}
79+
});

0 commit comments

Comments
 (0)