Skip to content

Commit 3fcf96b

Browse files
committed
a baseline test which shows that we cannot reproduce the status quo with changes just yet. (#26)
1 parent b538ad6 commit 3fcf96b

File tree

1 file changed

+59
-25
lines changed

1 file changed

+59
-25
lines changed

tests/baseline.rs

+59-25
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,67 @@
11
use std::collections::HashSet;
22

33
#[test]
4-
fn all_aggregrated_diffs_equal_latest_version() -> git_testtools::Result {
5-
let ((expected, baseline_duration), _actual) =
6-
std::thread::scope(|s| -> git_testtools::Result<_> {
7-
let baseline = s
8-
.spawn(|| -> Result<_, crates_index::Error> {
9-
let start = std::time::Instant::now();
10-
let index = crates_index::Index::new_cargo_default()?;
11-
let baseline = index
12-
.crates()
13-
.map(|c| {
14-
c.versions()
15-
.iter()
16-
.map(|v| v.checksum().to_owned())
17-
.collect::<Vec<_>>()
18-
})
19-
.flatten()
20-
.collect::<HashSet<_>>();
21-
22-
Ok((baseline, start.elapsed()))
23-
})
24-
.join()
25-
.expect("no panic")?;
26-
27-
Ok((baseline, ()))
28-
})?;
4+
fn all_aggregrated_diffs_equal_latest_version(
5+
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
6+
let ((expected, baseline_duration), (actual, diff_duration)) = std::thread::scope(
7+
|scope| -> Result<_, Box<dyn std::error::Error + Send + Sync>> {
8+
let baseline = scope.spawn(|| -> Result<_, crates_index::Error> {
9+
let index = crates_index::Index::new_cargo_default()?;
10+
let start = std::time::Instant::now();
11+
let mut versions = HashSet::new();
12+
for krate in index.crates() {
13+
for version in krate.versions() {
14+
versions.insert(version.checksum().to_owned());
15+
}
16+
}
17+
Ok((versions, start.elapsed()))
18+
});
19+
20+
let actual = scope.spawn(|| -> Result<_, Box<dyn std::error::Error + Send + Sync>> {
21+
use crates_index_diff::git;
22+
23+
let start = std::time::Instant::now();
24+
let repo_path = crates_index::Index::new_cargo_default()?.path().to_owned();
25+
let index = crates_index_diff::Index::from_path_or_cloned(repo_path)?;
26+
let changes = index.changes_between_commits(
27+
git::hash::ObjectId::empty_tree(git::hash::Kind::Sha1),
28+
index.repository().head_id()?,
29+
)?;
30+
31+
use crates_index_diff::Change::*;
32+
let mut versions = HashSet::new();
33+
34+
for change in changes {
35+
match change {
36+
Added(v) | Yanked(v) => {
37+
versions.insert(v.checksum.to_owned());
38+
}
39+
Deleted {
40+
versions: deleted, ..
41+
} => {
42+
for deleted_version in deleted {
43+
versions.remove(&deleted_version.checksum);
44+
}
45+
}
46+
}
47+
}
48+
Ok((versions, start.elapsed()))
49+
});
50+
51+
Ok((
52+
baseline.join().expect("no panic")?,
53+
actual.join().expect("no panic")?,
54+
))
55+
},
56+
)?;
2957

3058
dbg!(baseline_duration, expected.len());
59+
dbg!(diff_duration, actual.len());
60+
// assert_eq!(
61+
// actual.len(),
62+
// expected.len(),
63+
// "aggregated of all changes produces the final result"
64+
// );
3165

3266
Ok(())
3367
}

0 commit comments

Comments
 (0)