cob: Improve stability of test setup
We employ various tricks to ensure that tests are reproducible. In this case, having stable commit ids allows us to test specific traversal orders of a COB history in cases of concurrent updates.
This commit is contained in:
parent
69fe1d5989
commit
5709f5d886
|
|
@ -12,6 +12,11 @@ edition = "2021"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
keywords = ["radicle", "cob", "cobs"]
|
keywords = ["radicle", "cob", "cobs"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
# Only used for testing. Ensures that commit ids are stable.
|
||||||
|
stable-commit-ids = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fastrand = { version = "2.0.0" }
|
fastrand = { version = "2.0.0" }
|
||||||
log = { version = "0.4.17" }
|
log = { version = "0.4.17" }
|
||||||
|
|
|
||||||
|
|
@ -261,6 +261,7 @@ fn write_commit(
|
||||||
) -> Result<(Oid, Timestamp), error::Create> {
|
) -> Result<(Oid, Timestamp), error::Create> {
|
||||||
let trailers: Vec<OwnedTrailer> = vec![trailers::ResourceCommitTrailer::from(resource).into()];
|
let trailers: Vec<OwnedTrailer> = vec![trailers::ResourceCommitTrailer::from(resource).into()];
|
||||||
let author = repo.signature()?;
|
let author = repo.signature()?;
|
||||||
|
#[allow(unused_variables)]
|
||||||
let timestamp = author.when().seconds();
|
let timestamp = author.when().seconds();
|
||||||
|
|
||||||
let mut headers = Headers::new();
|
let mut headers = Headers::new();
|
||||||
|
|
@ -273,6 +274,15 @@ fn write_commit(
|
||||||
);
|
);
|
||||||
let author = Author::try_from(&author)?;
|
let author = Author::try_from(&author)?;
|
||||||
|
|
||||||
|
#[cfg(feature = "stable-commit-ids")]
|
||||||
|
// Ensures the commit id doesn't change on every run.
|
||||||
|
let (author, timestamp) = (
|
||||||
|
Author {
|
||||||
|
time: git_ext::author::Time::new(1514817556, 0),
|
||||||
|
..author
|
||||||
|
},
|
||||||
|
1514817556,
|
||||||
|
);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
let (author, timestamp) = if let Ok(s) = std::env::var(crate::git::RAD_COMMIT_TIME) {
|
let (author, timestamp) = if let Ok(s) = std::env::var(crate::git::RAD_COMMIT_TIME) {
|
||||||
// SAFETY: It's ok to panic here, since this is only enabled in debug mode.
|
// SAFETY: It's ok to panic here, since this is only enabled in debug mode.
|
||||||
|
|
|
||||||
|
|
@ -64,3 +64,8 @@ qcheck = { version = "1", default-features = false }
|
||||||
path = "../radicle-crypto"
|
path = "../radicle-crypto"
|
||||||
version = "0"
|
version = "0"
|
||||||
features = ["test"]
|
features = ["test"]
|
||||||
|
|
||||||
|
[dev-dependencies.radicle-cob]
|
||||||
|
path = "../radicle-cob"
|
||||||
|
version = "0"
|
||||||
|
features = ["stable-commit-ids"]
|
||||||
|
|
|
||||||
|
|
@ -92,15 +92,13 @@ pub mod setup {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let root = tempfile::tempdir().unwrap();
|
let root = tempfile::tempdir().unwrap();
|
||||||
|
|
||||||
Self::new(root)
|
Self::new(root, MockSigner::default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Node {
|
impl Node {
|
||||||
pub fn new(root: impl AsRef<Path>) -> Self {
|
pub fn new(root: impl AsRef<Path>, signer: MockSigner) -> Self {
|
||||||
let root = root.as_ref().to_path_buf();
|
let root = root.as_ref().to_path_buf();
|
||||||
let mut rng = fastrand::Rng::new();
|
|
||||||
let signer = MockSigner::new(&mut rng);
|
|
||||||
let home = root.join("home");
|
let home = root.join("home");
|
||||||
let paths = Home::new(home.as_path()).unwrap();
|
let paths = Home::new(home.as_path()).unwrap();
|
||||||
let storage = Storage::open(paths.storage()).unwrap();
|
let storage = Storage::open(paths.storage()).unwrap();
|
||||||
|
|
@ -138,10 +136,12 @@ pub mod setup {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeRepo {
|
impl NodeRepo {
|
||||||
|
#[track_caller]
|
||||||
pub fn fetch(&self, from: &Node) -> Vec<RefUpdate> {
|
pub fn fetch(&self, from: &Node) -> Vec<RefUpdate> {
|
||||||
super::fetch(&self.repo, from.signer.public_key(), Namespaces::All).unwrap()
|
super::fetch(&self.repo, from.signer.public_key(), Namespaces::All).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
pub fn checkout(&self) -> &NodeRepoCheckout {
|
pub fn checkout(&self) -> &NodeRepoCheckout {
|
||||||
self.checkout.as_ref().unwrap()
|
self.checkout.as_ref().unwrap()
|
||||||
}
|
}
|
||||||
|
|
@ -240,9 +240,9 @@ pub mod setup {
|
||||||
impl Default for Network {
|
impl Default for Network {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let alice = Node::new(tmp.path().join("alice"));
|
let alice = Node::new(tmp.path().join("alice"), MockSigner::from_seed([!0; 32]));
|
||||||
let mut bob = Node::new(tmp.path().join("bob"));
|
let mut bob = Node::new(tmp.path().join("bob"), MockSigner::from_seed([!1; 32]));
|
||||||
let mut eve = Node::new(tmp.path().join("eve"));
|
let mut eve = Node::new(tmp.path().join("eve"), MockSigner::from_seed([!2; 32]));
|
||||||
let repo = alice.project();
|
let repo = alice.project();
|
||||||
let rid = repo.id;
|
let rid = repo.id;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use crate::storage::git::Storage;
|
||||||
use crate::storage::refs::SignedRefs;
|
use crate::storage::refs::SignedRefs;
|
||||||
|
|
||||||
/// The birth of the radicle project, January 1st, 2018.
|
/// The birth of the radicle project, January 1st, 2018.
|
||||||
const RADICLE_EPOCH: i64 = 1514817556;
|
pub const RADICLE_EPOCH: i64 = 1514817556;
|
||||||
|
|
||||||
/// Create a new storage with a project.
|
/// Create a new storage with a project.
|
||||||
pub fn storage<P: AsRef<Path>, G: Signer>(path: P, signer: &G) -> Result<Storage, rad::InitError> {
|
pub fn storage<P: AsRef<Path>, G: Signer>(path: P, signer: &G) -> Result<Storage, rad::InitError> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue