test: add autobahn tests

Signed-off-by: Alexey Galakhov <agalakhov@snapview.de>
pull/1/head
Alexey Galakhov 6 years ago
parent e2cdf11bc8
commit 8b13cb7ad3
  1. 12
      .travis.yml
  2. 2
      Cargo.toml
  3. 3623
      autobahn/client-results.json
  4. 12
      autobahn/fuzzingclient.json
  5. 7
      autobahn/fuzzingserver.json
  6. 3637
      autobahn/server-results.json
  7. 73
      examples/autobahn-client.rs
  8. 49
      examples/autobahn-server.rs
  9. 32
      scripts/autobahn-client.sh
  10. 31
      scripts/autobahn-server.sh

@ -1 +1,13 @@
language: rust
before_script:
- export PATH="$PATH:$HOME/.cargo/bin"
script:
- cargo test --release
after_success:
- sudo apt-get install python-unittest2
- sudo pip install ghp-import urllib3[secure] autobahntestsuite
- echo "Running Autobahn TestSuite for client" && ./scripts/autobahn-client.sh
- echo "Running Autobahn TestSuite for server" && ./scripts/autobahn-server.sh

@ -47,3 +47,5 @@ version = "0.2.0"
[dev-dependencies]
tokio = "0.1.7"
url = "1.6.0"
env_logger = "0.6.1"
log = "0.4.6"

File diff suppressed because it is too large Load Diff

@ -0,0 +1,12 @@
{
"outdir": "./autobahn/server",
"servers": [
{
"agent": "Tungstenite",
"url": "ws://127.0.0.1:9002"
}
],
"cases": ["*"],
"exclude-cases": [],
"exclude-agent-cases": {}
}

@ -0,0 +1,7 @@
{
"url": "ws://127.0.0.1:9001",
"outdir": "./autobahn/client",
"cases": ["*"],
"exclude-cases": [],
"exclude-agent-cases": {}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,73 @@
#[macro_use] extern crate log;
extern crate env_logger;
extern crate futures;
extern crate tokio;
extern crate tokio_tungstenite;
extern crate url;
use url::Url;
use futures::{Future, Stream};
use tokio_tungstenite::{
connect_async,
tungstenite::{
connect,
Result,
Error as WsError,
},
};
const AGENT: &'static str = "Tungstenite";
fn get_case_count() -> Result<u32> {
let (mut socket, _) = connect(
Url::parse("ws://localhost:9001/getCaseCount").unwrap(),
)?;
let msg = socket.read_message()?;
socket.close(None)?;
Ok(msg.into_text()?.parse::<u32>().unwrap())
}
fn update_reports() -> Result<()> {
let (mut socket, _) = connect(
Url::parse(&format!("ws://localhost:9001/updateReports?agent={}", AGENT)).unwrap(),
)?;
socket.close(None)?;
Ok(())
}
fn run_test(case: u32) {
info!("Running test case {}", case);
let case_url = Url::parse(
&format!("ws://localhost:9001/runCase?case={}&agent={}", case, AGENT)
).unwrap();
let job = connect_async(case_url)
.map_err(|err| error!("Connect error: {}", err))
.and_then(|(ws_stream, _)| {
let (sink, stream) = ws_stream.split();
stream
.filter(|msg| msg.is_text() || msg.is_binary())
.forward(sink)
.and_then(|(_stream, _sink)| Ok(()))
.map_err(|err| {
match err {
WsError::ConnectionClosed => (),
err => info!("WS error {}", err),
}
})
});
tokio::run(job)
}
fn main() {
env_logger::init();
let total = get_case_count().unwrap();
for case in 1..(total + 1) {
run_test(case)
}
update_reports().unwrap();
}

@ -0,0 +1,49 @@
#[macro_use] extern crate log;
extern crate env_logger;
extern crate futures;
extern crate tokio;
extern crate tokio_tungstenite;
use futures::{Future, Stream};
use tokio::net::TcpListener;
use tokio_tungstenite::{
accept_async,
tungstenite::Error as WsError,
};
fn main() {
env_logger::init();
let mut runtime = tokio::runtime::Builder::new().build().unwrap();
let addr = "127.0.0.1:9002".parse().unwrap();
let socket = TcpListener::bind(&addr).unwrap();
info!("Listening on: {}", addr);
let srv = socket.incoming().map_err(Into::into).for_each(move |stream| {
let peer = stream.peer_addr().expect("connected streams should have a peer address");
info!("Peer address: {}", peer);
accept_async(stream).and_then(move |ws_stream| {
info!("New WebSocket connection: {}", peer);
let (sink, stream) = ws_stream.split();
let job = stream
.filter(|msg| msg.is_text() || msg.is_binary())
.forward(sink)
.and_then(|(_stream, _sink)| Ok(()))
.map_err(|err| {
match err {
WsError::ConnectionClosed => (),
err => info!("WS error: {}", err),
}
});
tokio::spawn(job);
Ok(())
})
});
runtime.block_on(srv).unwrap();
}

@ -0,0 +1,32 @@
#!/usr/bin/env bash
# Author michael <themichaeleden@gmail.com>
set -euo pipefail
set -x
SOURCE_DIR=$(readlink -f "${BASH_SOURCE[0]}")
SOURCE_DIR=$(dirname "$SOURCE_DIR")
cd "${SOURCE_DIR}/.."
function cleanup() {
kill -9 ${FUZZINGSERVER_PID}
}
trap cleanup TERM EXIT
function test_diff() {
if ! diff -q \
<(jq -S 'del(."Tungstenite" | .. | .duration?)' 'autobahn/client-results.json') \
<(jq -S 'del(."Tungstenite" | .. | .duration?)' 'autobahn/client/index.json')
then
echo 'Difference in results, either this is a regression or' \
'one should update autobahn/client-results.json with the new results.' \
'The results are:'
exit 64
fi
}
cargo build --release --example autobahn-client
wstest -m fuzzingserver -s 'autobahn/fuzzingserver.json' & FUZZINGSERVER_PID=$!
sleep 3
echo "Server PID: ${FUZZINGSERVER_PID}"
cargo run --release --example autobahn-client
test_diff

@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Author michael <themichaeleden@gmail.com>
set -euo pipefail
set -x
SOURCE_DIR=$(readlink -f "${BASH_SOURCE[0]}")
SOURCE_DIR=$(dirname "$SOURCE_DIR")
cd "${SOURCE_DIR}/.."
WSSERVER_PID=
function cleanup() {
kill -9 ${WSSERVER_PID}
}
trap cleanup TERM EXIT
function test_diff() {
if ! diff -q \
<(jq -S 'del(."Tungstenite" | .. | .duration?)' 'autobahn/client-results.json') \
<(jq -S 'del(."Tungstenite" | .. | .duration?)' 'autobahn/server/index.json')
then
echo Difference in results, either this is a regression or \
one should update autobahn/server-results.json with the new results.
exit 64
fi
}
cargo build --release --example autobahn-server
cargo run --release --example autobahn-server & WSSERVER_PID=$!
echo "Server PID: ${WSSERVER_PID}"
sleep 3
wstest -m fuzzingclient -s 'autobahn/fuzzingclient.json'
test_diff
Loading…
Cancel
Save