Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle: Fix flaky test due to randomness
cloudhead committed 2 years ago
commit 14c204a11fafcfcfc7511a1e5ad2df6a74ca11c7
parent d973fd42f2e04bdf8f9c33f5ddba2497a5c750cd
2 files changed +14 -11
modified radicle/src/cob/patch.rs
@@ -678,8 +678,8 @@ impl store::FromHistory for Patch {
                            // case of a rebase off the master branch, or a redaction of the
                            // merge.
                            let Ok(head) = repo.reference_oid(&op.author, &branch) else {
-
                                    continue;
-
                                };
+
                                continue;
+
                            };
                            if commit != head && !repo.is_ancestor_of(commit, head)? {
                                continue;
                            }
modified radicle/src/node/address/types.rs
@@ -49,25 +49,28 @@ impl<K: hash::Hash + Eq, V> AddressBook<K, V> {
        }
    }

-
    /// Cycle through the keys at random. The random cycle repeats ad-infintum.
-
    pub fn cycle(&self) -> impl Iterator<Item = &K> {
-
        self.shuffled().map(|(k, _)| k).cycle()
+
    /// Return a new address book with the given RNG.
+
    pub fn with(self, rng: fastrand::Rng) -> Self {
+
        Self {
+
            inner: self.inner,
+
            rng,
+
        }
    }
+
}

+
impl<K: hash::Hash + Eq + Ord, V> AddressBook<K, V> {
    /// Return a shuffled iterator over the keys.
    pub fn shuffled(&self) -> std::vec::IntoIter<(&K, &V)> {
        let mut items = self.inner.iter().collect::<Vec<_>>();
+
        items.sort_by_key(|(k, _)| *k);
        self.rng.shuffle(&mut items);

        items.into_iter()
    }

-
    /// Return a new address book with the given RNG.
-
    pub fn with(self, rng: fastrand::Rng) -> Self {
-
        Self {
-
            inner: self.inner,
-
            rng,
-
        }
+
    /// Cycle through the keys at random. The random cycle repeats ad-infintum.
+
    pub fn cycle(&self) -> impl Iterator<Item = &K> {
+
        self.shuffled().map(|(k, _)| k).cycle()
    }
}