-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements Autobahn tests against the WebSocket spec (#22)
* implement spec tests * update action * formatting * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * check for frame * Fix code styling
- Loading branch information
Showing
7 changed files
with
154 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: spec tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- '*.x' | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: true | ||
matrix: | ||
php: [8.2, 8.3] | ||
laravel: [10] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: dom, curl, libxml, mbstring, zip | ||
ini-values: error_reporting=E_ALL | ||
tools: composer:v2 | ||
coverage: none | ||
|
||
- name: Install dependencies | ||
run: | | ||
composer require "illuminate/contracts=^${{ matrix.laravel }}" --no-update | ||
composer update --prefer-dist --no-interaction --no-progress | ||
- name: Pull Autobahn Docker image | ||
run: docker pull crossbario/autobahn-testsuite | ||
|
||
- name: Start WebSocket server | ||
working-directory: tests/Specification | ||
run: php spec-server.php & | ||
|
||
- name: Run specification tests | ||
working-directory: tests/Specification | ||
run: | | ||
docker run --rm \ | ||
-v $PWD:/mnt/autobahn \ | ||
-v $PWD/reports:/mnt/autobahn/reports \ | ||
--add-host host.docker.internal:host-gateway \ | ||
crossbario/autobahn-testsuite \ | ||
wstest -m fuzzingclient -s /mnt/autobahn/client-spec.json | ||
- name: Analyze test results | ||
working-directory: tests/Specification | ||
run: php spec-analyze.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"options": { "failByDrop": false }, | ||
"outdir": "/mnt/autobahn/reports", | ||
"servers": [{ "agent": "Reverb", "url": "ws://host.docker.internal:8080", "options": { "version": 18 } }], | ||
"cases": ["*"], | ||
"exclude-cases": [ | ||
"12.*", | ||
"13.*" | ||
], | ||
"exclude-agent-cases": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Ratchet\RFC6455\Test; | ||
|
||
use Illuminate\Support\Arr; | ||
|
||
require __DIR__.'/../../vendor/autoload.php'; | ||
|
||
$hasFailures = false; | ||
|
||
if (! file_exists($file = __DIR__.'/reports/index.json')) { | ||
echo 'No test results found.'.PHP_EOL; | ||
|
||
exit(1); | ||
} | ||
|
||
$results = file_get_contents($file); | ||
$results = Arr::first(json_decode($results, true)); | ||
|
||
foreach ($results as $name => $result) { | ||
if ($result['behavior'] === 'INFORMATIONAL') { | ||
continue; | ||
} | ||
|
||
if (in_array($result['behavior'], ['OK', 'NON-STRICT'])) { | ||
echo '✅ Test case '.$name.' passed.'.PHP_EOL; | ||
} else { | ||
$hasFailures = true; | ||
echo '❌ Test case '.$name.' failed.'.PHP_EOL; | ||
} | ||
} | ||
|
||
exit($hasFailures ? 1 : 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
use Laravel\Reverb\Http\Route; | ||
use Laravel\Reverb\Http\Router; | ||
use Laravel\Reverb\Http\Server; | ||
use Laravel\Reverb\WebSockets\WsConnection; | ||
use Psr\Http\Message\RequestInterface; | ||
use React\EventLoop\Loop; | ||
use React\Socket\SocketServer; | ||
use Symfony\Component\Routing\Matcher\UrlMatcher; | ||
use Symfony\Component\Routing\RequestContext; | ||
use Symfony\Component\Routing\RouteCollection; | ||
|
||
require __DIR__.'/../../vendor/autoload.php'; | ||
|
||
$loop = Loop::get(); | ||
$socket = new SocketServer('0.0.0.0:8080', [], $loop); | ||
$router = new Router(new UrlMatcher(routes(), new RequestContext)); | ||
|
||
$server = new Server($socket, $router, $loop); | ||
|
||
echo "Server running at 0.0.0.0:8080\n"; | ||
|
||
$server->start(); | ||
|
||
function routes() | ||
{ | ||
$routes = new RouteCollection; | ||
$routes->add( | ||
'sockets', | ||
Route::get('/', function (RequestInterface $request, WsConnection $connection) { | ||
$connection->onMessage(function ($message) use ($connection) { | ||
$connection->send($message); | ||
}); | ||
$connection->openBuffer(); | ||
}) | ||
); | ||
|
||
return $routes; | ||
} |