Skip to content

Commit dabcd91

Browse files
committed
fix(quake): skip latency emulation on WSL2
1 parent c639319 commit dabcd91

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

crates/quake/src/latency.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ fn generate_tc_script(
169169

170170
script.push_str("set -e\n\n");
171171

172+
script
173+
.push_str("# WSL2 kernels often do not include the qdisc modules required by tc netem.\n");
174+
script.push_str("if grep -qi microsoft /proc/sys/kernel/osrelease 2> /dev/null; then\n");
175+
script.push_str(" echo \"WSL2 detected; skipping tc latency emulation.\"\n");
176+
script.push_str(" exit 0\n");
177+
script.push_str("fi\n\n");
178+
172179
// Install iproute2 and iptables if ip or tc commands are missing (e.g. release images)
173180
script.push_str("if [ -f /etc/debian_version ] && ! which ip tc > /dev/null; then\n");
174181
script.push_str(" (apt-get update -qq && apt-get install -y -qq --no-install-recommends iproute2 iptables) >/dev/null 2>&1\n");
@@ -287,6 +294,37 @@ fn generate_tc_script(
287294
Ok(script)
288295
}
289296

297+
#[cfg(test)]
298+
mod tests {
299+
use super::*;
300+
301+
#[test]
302+
fn generated_tc_script_skips_latency_emulation_on_wsl2() {
303+
let node_name = "validator1".to_string();
304+
let mut node_regions = IndexMap::new();
305+
node_regions.insert(node_name.clone(), Region::UsEast1);
306+
307+
let script = generate_tc_script(
308+
&node_name,
309+
&Region::UsEast1,
310+
&node_regions,
311+
&NodesMetadata::default(),
312+
)
313+
.expect("script generation should succeed");
314+
315+
let wsl_guard = script
316+
.find("grep -qi microsoft /proc/sys/kernel/osrelease")
317+
.expect("script should detect WSL2");
318+
let tc_setup = script
319+
.find("tc qdisc add dev $IF root handle 1: htb default 10")
320+
.expect("script should still configure tc on supported hosts");
321+
322+
assert!(wsl_guard < tc_setup);
323+
assert!(script.contains("WSL2 detected; skipping tc latency emulation."));
324+
assert!(script.contains("exit 0"));
325+
}
326+
}
327+
290328
/// Generate and save latency scripts for all nodes
291329
pub fn generate_latency_scripts(
292330
testnet_dir: &Path,

0 commit comments

Comments
 (0)