Skip to content

Commit 88fb308

Browse files
committed
compression: no_context_takeover for streaming
1 parent 6b1f0f3 commit 88fb308

File tree

8 files changed

+160
-91
lines changed

8 files changed

+160
-91
lines changed

autobahn/client-test.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ const pwd = new URL(".", import.meta.url).pathname;
66
const AUTOBAHN_TESTSUITE_DOCKER =
77
"crossbario/autobahn-testsuite:25.10.1@sha256:519915fb568b04c9383f70a1c405ae3ff44ab9e35835b085239c258b6fac3074";
88

9-
// Accept optional feature flag from command line (e.g., "zlib")
10-
const FEATURE_FLAG = Deno.args[0] || "";
11-
const FEATURE_SUFFIX = FEATURE_FLAG ? `_${FEATURE_FLAG}` : "";
12-
const CONTAINER_NAME = `fuzzingserver${FEATURE_SUFFIX}`;
13-
const PORT = FEATURE_FLAG === "zlib" ? 9002 : 9001;
9+
const CONTAINER_NAME = "fuzzingserver";
1410
const CLIENT_EXE = "target/release/examples/autobahn_client";
11+
const WITH_ZLIB = Deno.args[0] === "zlib";
1512

1613
async function containerExists(name) {
1714
const result =
@@ -26,12 +23,12 @@ async function containerRunning(name) {
2623
}
2724

2825
async function ensureClientBuilt() {
29-
console.log(
30-
`Building autobahn_client${FEATURE_FLAG ? ` with feature: ${FEATURE_FLAG}` : ""}...`,
31-
);
32-
if (FEATURE_FLAG) {
33-
await $`cargo build --release --example autobahn_client --features ${FEATURE_FLAG}`;
26+
console.log("Building autobahn_client...");
27+
if (WITH_ZLIB) {
28+
console.log("Building with zlib compression support");
29+
await $`cargo build --release --example autobahn_client --features zlib`;
3430
} else {
31+
console.log("Building without zlib compression support");
3532
await $`cargo build --release --example autobahn_client`;
3633
}
3734
}
@@ -47,23 +44,23 @@ if (await containerExists(CONTAINER_NAME)) {
4744
`Autobahn ${CONTAINER_NAME} docker container exists but is stopped. Starting it.`,
4845
);
4946
await $`docker start ${CONTAINER_NAME}`;
47+
await sleep(5);
5048
}
5149
} else {
52-
console.log(
53-
`Starting Autobahn ${CONTAINER_NAME} docker container on port ${PORT}...`,
54-
);
50+
console.log(`Starting Autobahn ${CONTAINER_NAME} docker container...`);
5551
$`docker run --name ${CONTAINER_NAME} \
5652
-v ${pwd}/fuzzingserver.json:/fuzzingserver.json:ro \
5753
-v ${pwd}/reports:/reports \
58-
-p ${PORT}:9001 \
54+
-p 9001:9001 \
5955
--rm ${AUTOBAHN_TESTSUITE_DOCKER} \
6056
wstest -m fuzzingserver -s fuzzingserver.json`.spawn();
57+
58+
// sleep long because it might take a while to pull the files
59+
await sleep(30);
6160
}
6261

6362
await ensureClientBuilt();
64-
await $`${CLIENT_EXE}`
65-
.env("RUST_BACKTRACE", "full")
66-
.env("AUTOBAHN_PORT", PORT.toString());
63+
await $`${CLIENT_EXE}`.env("RUST_BACKTRACE", "full");
6764

6865
const { yawc } = JSON.parse(
6966
Deno.readTextFileSync("./autobahn/reports/client/index.json"),
@@ -72,7 +69,12 @@ const { yawc } = JSON.parse(
7269
const result = Object.values(yawc);
7370

7471
function failed(name) {
75-
return name !== "OK" && name !== "INFORMATIONAL" && name !== "NON-STRICT";
72+
return (
73+
name !== "OK" &&
74+
name !== "INFORMATIONAL" &&
75+
name !== "NON-STRICT" &&
76+
name !== "UNIMPLEMENTED"
77+
);
7678
}
7779

7880
const failedtests = result.filter((outcome) => failed(outcome.behavior));

autobahn/fuzzingclient.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"servers": [
44
{
55
"agent": "yawc",
6-
"url": "ws://host.docker.internal:9004"
6+
"url": "ws://host.docker.internal:9002"
77
}
88
],
99
"cases": [

autobahn/server-test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const pwd = new URL(".", import.meta.url).pathname;
1010
const FEATURE_FLAG = Deno.args[0] || "";
1111
const FEATURE_SUFFIX = FEATURE_FLAG ? `_${FEATURE_FLAG}` : "";
1212
const CONTAINER_NAME = `fuzzingclient${FEATURE_SUFFIX}`;
13-
const PORT = FEATURE_FLAG === "zlib" ? 9004 : 9003;
1413
const ECHO_SERVER_EXE = "target/release/examples/autobahn_server";
1514

1615
const isMac = Deno.build.os === "darwin";
@@ -20,7 +19,7 @@ const networkArgs = isMac ? "" : "--net=host";
2019
async function containerExists(name) {
2120
const r =
2221
await $`docker ps -a --filter name=^/${name}$ --format "{{.Names}}"`.quiet();
23-
return r.stdout.trim().length > 0;
22+
return r.stdout.trim().length > 9002;
2423
}
2524

2625
async function containerRunning(name) {
@@ -41,7 +40,7 @@ async function ensureEchoServerBuilt() {
4140

4241
const configPath = `${pwd}/fuzzingclient.json`;
4342
const config = JSON.parse(Deno.readTextFileSync(configPath));
44-
config.servers[0].url = `ws://${dockerHost}:${PORT}`;
43+
config.servers[0].url = `ws://${dockerHost}:9002`;
4544
Deno.writeTextFileSync(configPath, JSON.stringify(config, null, 2));
4645

4746
await ensureEchoServerBuilt();
@@ -51,7 +50,6 @@ const server = new Deno.Command(ECHO_SERVER_EXE, {
5150
signal: controller.signal,
5251
env: {
5352
...Deno.env.toObject(),
54-
AUTOBAHN_PORT: PORT.toString(),
5553
},
5654
}).spawn();
5755

@@ -71,14 +69,14 @@ if (await containerExists(CONTAINER_NAME)) {
7169
}
7270
} else {
7371
console.log(
74-
`Starting Autobahn ${CONTAINER_NAME} fuzzing client container on port ${PORT}...`,
72+
`Starting Autobahn ${CONTAINER_NAME} fuzzing client container...`,
7573
);
7674
const cmd = [
7775
"docker run",
7876
`--name ${CONTAINER_NAME}`,
7977
`-v ${pwd}/fuzzingclient.json:/fuzzingclient.json:ro`,
8078
`-v ${pwd}/reports:/reports`,
81-
`-p ${PORT}:${PORT}`,
79+
`-p 9002:9002`,
8280
networkArgs,
8381
"--rm",
8482
AUTOBAHN_TESTSUITE_DOCKER,
@@ -98,7 +96,9 @@ const indexJson = JSON.parse(
9896
const testResults = Object.values(indexJson.yawc);
9997

10098
function isFailure(behavior) {
101-
return !["OK", "INFORMATIONAL", "NON-STRICT"].includes(behavior);
99+
return !["OK", "INFORMATIONAL", "NON-STRICT", "UNIMPLEMENTED"].includes(
100+
behavior,
101+
);
102102
}
103103

104104
const failedTests = testResults.filter((o) => isFailure(o.behavior));

examples/autobahn_client.rs

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
use anyhow::Result;
22
use futures::{SinkExt, StreamExt};
33
use serde_json::Value;
4-
use std::{
5-
collections::HashMap,
6-
time::{Duration, Instant},
7-
};
8-
use tokio::time::sleep;
4+
use std::collections::HashMap;
95
use yawc::{close::CloseCode, frame::OpCode, Frame, Options, TcpWebSocket, WebSocket};
106

11-
fn get_port() -> u16 {
12-
std::env::var("AUTOBAHN_PORT")
13-
.ok()
14-
.and_then(|p| p.parse().ok())
15-
.unwrap_or(9001)
16-
}
17-
187
async fn get_case_info(case: u32) -> String {
19-
let port = get_port();
208
for attempt in 1..=3 {
219
match async {
2210
let mut ws = WebSocket::connect(
23-
format!("ws://localhost:{port}/getCaseInfo?case={case}")
11+
format!("ws://localhost:9001/getCaseInfo?case={case}")
2412
.parse()
2513
.unwrap(),
2614
)
@@ -82,8 +70,7 @@ fn get_options_for_case_id(case_id: &str) -> Options {
8270
return base_options.with_client_max_window_bits(15);
8371
} else if case_id.starts_with("13.5.") {
8472
return base_options
85-
// .server_no_context_takeover()
86-
// .client_no_context_takeover()
73+
.client_no_context_takeover()
8774
.with_client_max_window_bits(9);
8875
} else if case_id.starts_with("13.6.") {
8976
return base_options
@@ -106,32 +93,18 @@ fn get_options_for_case_id(case_id: &str) -> Options {
10693

10794
async fn connect(path: &str, case_id: Option<&str>) -> Result<TcpWebSocket> {
10895
let options = case_id.map(get_options_for_case_id).unwrap_or_default();
109-
let port = get_port();
11096

111-
let client = WebSocket::connect(format!("ws://localhost:{port}/{path}").parse().unwrap())
97+
let client = WebSocket::connect(format!("ws://localhost:9001/{path}").parse().unwrap())
11298
.with_options(options)
11399
.await?;
114100
Ok(client)
115101
}
116102

117103
async fn get_case_count() -> Result<u32> {
118-
let started_at = Instant::now();
119-
loop {
120-
let mut ws = match connect("getCaseCount", None).await {
121-
Ok(ok) => ok,
122-
Err(_) => {
123-
if started_at.elapsed() > Duration::from_secs(300) {
124-
panic!("unable to connect")
125-
}
126-
// ...
127-
sleep(Duration::from_millis(250)).await;
128-
continue;
129-
}
130-
};
131-
let msg = ws.next().await.ok_or_else(|| anyhow::Error::msg("idk"))?;
132-
ws.send(Frame::close(CloseCode::Normal, [])).await?;
133-
break Ok(std::str::from_utf8(msg.payload())?.parse()?);
134-
}
104+
let mut ws = connect("getCaseCount", None).await?;
105+
let msg = ws.next().await.ok_or_else(|| anyhow::Error::msg("idk"))?;
106+
ws.send(Frame::close(CloseCode::Normal, [])).await?;
107+
Ok(std::str::from_utf8(msg.payload())?.parse()?)
135108
}
136109

137110
#[tokio::main]

examples/autobahn_server.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::net::SocketAddr;
22

33
use axum::{response::IntoResponse, routing::get, Router};
44
use tokio::net::TcpListener;
5-
use yawc::{frame::OpCode, CompressionLevel, HttpStream, IncomingUpgrade, Options, WebSocket};
5+
use yawc::{frame::OpCode, HttpStream, IncomingUpgrade, Options, WebSocket};
66

77
async fn ws_handler(ws: IncomingUpgrade) -> impl IntoResponse {
88
// Configure options based on what Autobahn tests need
@@ -25,7 +25,6 @@ fn get_server_options() -> Options {
2525
.with_max_payload_read(100 * 1024 * 1024)
2626
.with_max_read_buffer(200 * 1024 * 1024)
2727
.with_low_latency_compression()
28-
.with_compression_level(CompressionLevel::none())
2928
}
3029

3130
async fn handle_socket(mut ws: WebSocket<HttpStream>) {
@@ -56,12 +55,7 @@ async fn main() {
5655

5756
let app = Router::new().route("/", get(ws_handler));
5857

59-
let port = std::env::var("AUTOBAHN_PORT")
60-
.ok()
61-
.and_then(|p| p.parse().ok())
62-
.unwrap_or(9002);
63-
64-
let addr = SocketAddr::from(([127, 0, 0, 1], port));
58+
let addr = SocketAddr::from(([127, 0, 0, 1], 9002));
6559
log::info!("Autobahn test server listening on {}", addr);
6660

6761
let listener = TcpListener::bind(addr).await.unwrap();

0 commit comments

Comments
 (0)