@@ -223,8 +223,9 @@ impl FeatureProbe {
223223 Some ( toggle) => toggle. track_access_events ( ) ,
224224 None => false ,
225225 } ;
226- self . record_access ( toggle, user, track_access_events, & detail) ;
227- self . record_debug ( toggle, user, debug_until_time, & detail) ;
226+ let ts = unix_timestamp ( ) ;
227+ self . record_access ( toggle, user, track_access_events, & detail, ts) ;
228+ self . record_debug ( toggle, user, debug_until_time, & detail, ts) ;
228229 if let Some ( mut detail) = detail {
229230 detail. debug_until_time = debug_until_time;
230231 return Some ( detail) ;
@@ -238,13 +239,14 @@ impl FeatureProbe {
238239 user : & FPUser ,
239240 track_access_events : bool ,
240241 detail : & Option < EvalDetail < Value > > ,
242+ ts : u128 ,
241243 ) -> Option < ( ) > {
242244 let recorder = self . event_recorder . as_ref ( ) ?;
243245 let detail = detail. as_ref ( ) ?;
244246 let value = detail. value . as_ref ( ) ?;
245247 let event = AccessEvent {
246248 kind : "access" . to_string ( ) ,
247- time : unix_timestamp ( ) ,
249+ time : ts ,
248250 key : toggle. to_owned ( ) ,
249251 user : user. key ( ) ,
250252 value : value. clone ( ) ,
@@ -263,15 +265,16 @@ impl FeatureProbe {
263265 user : & FPUser ,
264266 debug_until_time : Option < u64 > ,
265267 detail : & Option < EvalDetail < Value > > ,
268+ ts : u128 ,
266269 ) -> Option < ( ) > {
267270 let recorder = self . event_recorder . as_ref ( ) ?;
268271 let detail = detail. as_ref ( ) ?;
269272 let value = detail. value . as_ref ( ) ?;
270273 if let Some ( debug_until_time) = debug_until_time {
271- if debug_until_time as u128 >= unix_timestamp ( ) {
274+ if debug_until_time as u128 >= ts {
272275 let debug = DebugEvent {
273276 kind : "debug" . to_string ( ) ,
274- time : unix_timestamp ( ) ,
277+ time : ts ,
275278 key : toggle. to_owned ( ) ,
276279 user : user. key ( ) ,
277280 user_detail : serde_json:: to_value ( user) . unwrap ( ) ,
@@ -493,6 +496,16 @@ mod tests {
493496 assert_eq ! ( fp. string_value( "toggle_3" , & u, "val" . to_owned( ) ) , "value" ) ;
494497 }
495498
499+ #[ test]
500+ fn test_feature_probe_track ( ) {
501+ let json = load_local_json ( "resources/fixtures/repo.json" ) ;
502+ let mut repo = json. unwrap ( ) ;
503+ repo. debug_until_time = Some ( unix_timestamp ( ) as u64 + 60 * 1000 ) ;
504+ let fp = FeatureProbe :: new_with ( "secret key" . to_string ( ) , repo) ;
505+ let u = FPUser :: new ( ) . with ( "name" , "bob" ) . with ( "city" , "1" ) ;
506+ fp. bool_value ( "bool_toggle" , & u, false ) ;
507+ }
508+
496509 fn load_local_json ( file : & str ) -> Result < Repository , FPError > {
497510 let mut path = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
498511 path. push ( file) ;
0 commit comments