MCPcopy Create free account
hub / github.com/aws/clock-bound / feed_two_events

Function feed_two_events

clock-bound/src/daemon/clock_sync_algorithm/ff/ntp.rs:807–862  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

805
806 #[test]
807 fn feed_two_events() {
808 let mut ff = Ntp::new(Duration::from_secs(50), Skew::from_ppm(15.0));
809
810 let event1 = event::Ntp::builder()
811 .tsc_pre(TscCount::new(1_000_000_000))
812 .tsc_post(TscCount::new(1_000_001_000))
813 .ntp_data(event::NtpData {
814 server_recv_time: Instant::from_days(1)
815 + Duration::from_secs(1)
816 + Duration::from_nanos(100),
817 server_send_time: Instant::from_days(1)
818 + Duration::from_secs(1)
819 + Duration::from_nanos(900),
820 root_delay: Duration::from_micros(15),
821 root_dispersion: Duration::from_micros(27),
822 stratum: Stratum::TWO,
823 })
824 .build()
825 .unwrap();
826
827 let event2 = event::Ntp::builder()
828 .tsc_pre(TscCount::new(2_000_000_000))
829 .tsc_post(TscCount::new(2_000_001_000))
830 .ntp_data(event::NtpData {
831 server_recv_time: Instant::from_days(1)
832 + Duration::from_secs(2)
833 + Duration::from_nanos(100),
834 server_send_time: Instant::from_days(1)
835 + Duration::from_secs(2)
836 + Duration::from_nanos(900),
837 root_delay: Duration::from_micros(15),
838 root_dispersion: Duration::from_micros(17),
839 stratum: Stratum::TWO,
840 })
841 .build()
842 .unwrap();
843
844 let result = ff.feed(event1.clone());
845 assert!(result.is_none());
846
847 let result = ff.feed(event2.clone());
848 let clock_params = result.unwrap();
849
850 let expected_time = event2
851 .data()
852 .server_recv_time
853 .midpoint(event2.data().server_send_time);
854 assert_eq!(clock_params.time, expected_time);
855
856 // events are symmetric RTT and at 1GHz
857 approx::assert_abs_diff_eq!(clock_params.period.get(), 1e-9);
858
859 // clock_error_bound should be max value
860 let expected_ceb = event1.calculate_clock_error_bound(clock_params.period);
861 assert_eq!(clock_params.clock_error_bound, expected_ceb);
862 }
863}

Callers

nothing calls this directly

Calls 8

midpointMethod · 0.80
newFunction · 0.50
buildMethod · 0.45
tsc_postMethod · 0.45
tsc_preMethod · 0.45
feedMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected