@@ -82,24 +82,32 @@ mod tests {
8282 use super :: * ;
8383 use crate :: tools:: cron:: { CronStore , Schedule } ;
8484
85+ fn unix_now ( ) -> u64 {
86+ std:: time:: SystemTime :: now ( )
87+ . duration_since ( std:: time:: UNIX_EPOCH )
88+ . map ( |d| d. as_secs ( ) )
89+ . unwrap_or ( 0 )
90+ }
91+
8592 #[ tokio:: test]
8693 async fn tick_fires_due_direct_job ( ) {
8794 let dir = std:: env:: temp_dir ( ) . join ( "icrab_cron_runner_direct" ) ;
8895 let _ = std:: fs:: remove_dir_all ( & dir) ;
8996 std:: fs:: create_dir_all ( & dir) . unwrap ( ) ;
9097 let store = CronStore :: empty ( & dir) ;
98+ let base = unix_now ( ) ;
9199 store
92100 . add (
93101 None ,
94102 "Reminder" . to_string ( ) ,
95103 JobAction :: Direct ,
96- Schedule :: Once { at_unix : 100 } ,
104+ Schedule :: Once { at_unix : base + 60 } ,
97105 12345 ,
98106 )
99107 . unwrap ( ) ;
100108 let ( inbound_tx, _inbound_rx) = mpsc:: channel ( 8 ) ;
101109 let ( outbound_tx, mut outbound_rx) = mpsc:: channel ( 8 ) ;
102- tick_once ( & store, & inbound_tx, & outbound_tx, 500 ) . await ;
110+ tick_once ( & store, & inbound_tx, & outbound_tx, base + 61 ) . await ;
103111 let msg = outbound_rx. try_recv ( ) . unwrap ( ) ;
104112 assert_eq ! ( msg. chat_id, 12345 ) ;
105113 assert_eq ! ( msg. text, "Reminder" ) ;
@@ -116,18 +124,19 @@ mod tests {
116124 let _ = std:: fs:: remove_dir_all ( & dir) ;
117125 std:: fs:: create_dir_all ( & dir) . unwrap ( ) ;
118126 let store = CronStore :: empty ( & dir) ;
127+ let base = unix_now ( ) ;
119128 store
120129 . add (
121130 None ,
122131 "Agent task" . to_string ( ) ,
123132 JobAction :: Agent ,
124- Schedule :: Once { at_unix : 100 } ,
133+ Schedule :: Once { at_unix : base + 60 } ,
125134 999 ,
126135 )
127136 . unwrap ( ) ;
128137 let ( inbound_tx, mut inbound_rx) = mpsc:: channel ( 8 ) ;
129138 let ( outbound_tx, _outbound_rx) = mpsc:: channel ( 8 ) ;
130- tick_once ( & store, & inbound_tx, & outbound_tx, 500 ) . await ;
139+ tick_once ( & store, & inbound_tx, & outbound_tx, base + 61 ) . await ;
131140 let msg = inbound_rx. try_recv ( ) . unwrap ( ) ;
132141 assert_eq ! ( msg. chat_id, 999 ) ;
133142 assert_eq ! ( msg. text, "Agent task" ) ;
@@ -142,18 +151,19 @@ mod tests {
142151 let _ = std:: fs:: remove_dir_all ( & dir) ;
143152 std:: fs:: create_dir_all ( & dir) . unwrap ( ) ;
144153 let store = CronStore :: empty ( & dir) ;
154+ let base = unix_now ( ) ;
145155 store
146156 . add (
147157 None ,
148158 "Later" . to_string ( ) ,
149159 JobAction :: Direct ,
150- Schedule :: Once { at_unix : 99999 } ,
160+ Schedule :: Once { at_unix : base + 1000 } ,
151161 1 ,
152162 )
153163 . unwrap ( ) ;
154164 let ( inbound_tx, _inbound_rx) = mpsc:: channel ( 8 ) ;
155165 let ( outbound_tx, mut outbound_rx) = mpsc:: channel ( 8 ) ;
156- tick_once ( & store, & inbound_tx, & outbound_tx, 500 ) . await ;
166+ tick_once ( & store, & inbound_tx, & outbound_tx, base + 500 ) . await ;
157167 assert ! ( outbound_rx. try_recv( ) . is_err( ) ) ;
158168 let _ = std:: fs:: remove_dir_all ( & dir) ;
159169 }
0 commit comments