generated from EmbarkStudios/opensource-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bcb4f9
commit 05ade46
Showing
4 changed files
with
303 additions
and
21 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/target | ||
**/target | ||
**/*.rs.bk | ||
Cargo.lock | ||
tests/flock/target |
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,7 @@ | ||
[package] | ||
name = "connect" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] |
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,89 @@ | ||
//! Runs the sparse reuses_connection test to ensure we aren't creating too many | ||
//! connections as a repro for https://github.com/EmbarkStudios/tame-index/issues/46 | ||
fn main() { | ||
// Build the binary so we know it's up to date, and so we can use the one | ||
// last modified in the target directory | ||
assert!( | ||
std::process::Command::new("cargo") | ||
.args([ | ||
"test", | ||
"--no-run", | ||
"--test", | ||
"sparse", | ||
"--features", | ||
"sparse" | ||
]) | ||
.status() | ||
.unwrap() | ||
.success(), | ||
"failed to build test binary" | ||
); | ||
|
||
let mut latest = std::path::PathBuf::new(); | ||
let mut ts = std::time::SystemTime::UNIX_EPOCH; | ||
|
||
for entry in std::fs::read_dir("target/debug/deps").expect("failed to read deps") { | ||
let entry = entry.expect("failed to read entry"); | ||
|
||
if !entry | ||
.file_name() | ||
.as_os_str() | ||
.to_str() | ||
.unwrap() | ||
.starts_with("sparse-") | ||
{ | ||
continue; | ||
} | ||
|
||
let md = entry.metadata().expect("failed to get metadata"); | ||
|
||
let mt = md.modified().expect("failed to get mod time"); | ||
|
||
if mt < ts { | ||
continue; | ||
} | ||
|
||
latest = entry.path(); | ||
ts = mt; | ||
} | ||
|
||
assert!( | ||
std::process::Command::new("strace") | ||
.args([ | ||
"-f", | ||
"-e", | ||
"trace=connect", | ||
"-o", | ||
"/tmp/tame-index-connection-trace" | ||
]) | ||
.arg(latest) | ||
.arg("reuses_connection") | ||
.status() | ||
.unwrap() | ||
.success(), | ||
"failed to strace test" | ||
); | ||
|
||
let trace = std::fs::read_to_string("/tmp/tame-index-connection-trace") | ||
.expect("failed to read strace output"); | ||
|
||
let connection_counts = trace | ||
.lines() | ||
.filter(|line| line.contains("connect(")) | ||
.count(); | ||
|
||
// The connection count should be roughly the same as the processor count | ||
let stdout = std::process::Command::new("nproc").output().unwrap().stdout; | ||
|
||
let proc_count: usize = std::str::from_utf8(&stdout) | ||
.unwrap() | ||
.trim() | ||
.parse() | ||
.unwrap(); | ||
let max = proc_count + 5; | ||
assert!( | ||
connection_counts <= max, | ||
"connection syscalls ({connection_counts}) should be lower than {max}" | ||
); | ||
} |
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