Skip to content

Commit 7b4889e

Browse files
committed
fix some flaky tests
1 parent 2d624dc commit 7b4889e

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

lightning/src/util/persist.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl From<OutPoint> for MonitorName {
290290
}
291291

292292
/// A struct representing a name for an update.
293-
#[derive(Clone, Debug)]
293+
#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
294294
pub struct UpdateName(String);
295295

296296
impl UpdateName {
@@ -684,6 +684,13 @@ mod tests {
684684
assert!(persister.kv.remove("namespace", "key",).is_err());
685685
}
686686

687+
fn is_sorted<T>(data: &[T]) -> bool
688+
where
689+
T: Ord,
690+
{
691+
data.windows(2).all(|w| w[0] <= w[1])
692+
}
693+
687694
// =================================
688695
// TESTS
689696
// =================================
@@ -748,8 +755,8 @@ mod tests {
748755
// Test that these monitors are found where they should be.
749756
let listed_monitor_names = persister.list_monitor_names().unwrap();
750757
assert_eq!(listed_monitor_names.len(), 2);
751-
assert_eq!(listed_monitor_names[0].0, "deadb33f_0");
752-
assert_eq!(listed_monitor_names[1].0, "feedbeef_1");
758+
assert!(listed_monitor_names.iter().any(|m| m.0 == "deadb33f_0"));
759+
assert!(listed_monitor_names.iter().any(|m| m.0 == "feedbeef_1"));
753760
}
754761

755762
#[test]
@@ -786,28 +793,20 @@ mod tests {
786793
index: 1,
787794
};
788795
let monitor_name = MonitorName::try_from(outpoint).unwrap();
789-
// Write a fake update at the expected location
790-
persister
791-
.kv
792-
.write(
793-
&persister.monitor_update_namespace(&monitor_name),
794-
"00000000000000000021",
795-
&[0],
796-
)
797-
.unwrap();
798-
persister
796+
for i in 2..=1000 {
797+
persister
799798
.kv
800799
.write(
801800
&persister.monitor_update_namespace(&monitor_name),
802-
"00000000000000000022",
801+
&UpdateName::from(i).storage_key(),
803802
&[0],
804803
)
805804
.unwrap();
805+
}
806806
// Check that we get the right number of updates, in order
807807
let listed_update_names = persister.list_update_names(&monitor_name).unwrap();
808-
assert_eq!(listed_update_names.len(), 2);
809-
assert_eq!(listed_update_names[0].0, "00000000000000000021");
810-
assert_eq!(listed_update_names[1].0, "00000000000000000022");
808+
assert_eq!(listed_update_names.len(), 999);
809+
assert!(is_sorted(&listed_update_names));
811810
}
812811

813812
#[test]

0 commit comments

Comments
 (0)