@@ -290,7 +290,7 @@ impl From<OutPoint> for MonitorName {
290
290
}
291
291
292
292
/// A struct representing a name for an update.
293
- #[ derive( Clone , Debug ) ]
293
+ #[ derive( Clone , Debug , PartialEq , PartialOrd , Eq , Ord ) ]
294
294
pub struct UpdateName ( String ) ;
295
295
296
296
impl UpdateName {
@@ -684,6 +684,13 @@ mod tests {
684
684
assert ! ( persister. kv. remove( "namespace" , "key" , ) . is_err( ) ) ;
685
685
}
686
686
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
+
687
694
// =================================
688
695
// TESTS
689
696
// =================================
@@ -748,8 +755,8 @@ mod tests {
748
755
// Test that these monitors are found where they should be.
749
756
let listed_monitor_names = persister. list_monitor_names ( ) . unwrap ( ) ;
750
757
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" ) ) ;
753
760
}
754
761
755
762
#[ test]
@@ -786,28 +793,20 @@ mod tests {
786
793
index : 1 ,
787
794
} ;
788
795
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
799
798
. kv
800
799
. write (
801
800
& persister. monitor_update_namespace ( & monitor_name) ,
802
- "00000000000000000022" ,
801
+ & UpdateName :: from ( i ) . storage_key ( ) ,
803
802
& [ 0 ] ,
804
803
)
805
804
. unwrap ( ) ;
805
+ }
806
806
// Check that we get the right number of updates, in order
807
807
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) ) ;
811
810
}
812
811
813
812
#[ test]
0 commit comments