@@ -676,13 +676,15 @@ def will_be_sampled_by_sdk
676676
677677 context "with X-Request-Start header" do
678678 it "attaches queue time to transaction" do
679- timestamp = Time . now . to_f - 0.05 # 50ms ago
680- env [ "HTTP_X_REQUEST_START" ] = "t=#{ timestamp } "
679+ Timecop . freeze do
680+ timestamp = Time . now . to_f - 0.05 # 50ms ago
681+ env [ "HTTP_X_REQUEST_START" ] = "t=#{ timestamp } "
681682
682- stack . call ( env )
683+ stack . call ( env )
683684
684- queue_time = transaction . contexts . dig ( :trace , :data , 'http.server.request.time_in_queue' )
685- expect ( queue_time ) . to be_within ( 10 ) . of ( 50 )
685+ queue_time = transaction . contexts . dig ( :trace , :data , 'http.server.request.time_in_queue' )
686+ expect ( queue_time ) . to be_within ( 10 ) . of ( 50 )
687+ end
686688 end
687689
688690 it "subtracts puma.request_body_wait" do
@@ -725,14 +727,16 @@ def will_be_sampled_by_sdk
725727 end
726728
727729 it "handles different timestamp formats" do
728- # Heroku/HAProxy microseconds format
729- timestamp_us = ( ( Time . now . to_f - 0.03 ) * 1_000_000 ) . to_i
730- env [ "HTTP_X_REQUEST_START" ] = "t=#{ timestamp_us } "
730+ Timecop . freeze do
731+ # Heroku/HAProxy microseconds format
732+ timestamp_us = ( ( Time . now . to_f - 0.03 ) * 1_000_000 ) . to_i
733+ env [ "HTTP_X_REQUEST_START" ] = "t=#{ timestamp_us } "
731734
732- stack . call ( env )
735+ stack . call ( env )
733736
734- queue_time = transaction . contexts . dig ( :trace , :data , 'http.server.request.time_in_queue' )
735- expect ( queue_time ) . to be_within ( 10 ) . of ( 30 )
737+ queue_time = transaction . contexts . dig ( :trace , :data , 'http.server.request.time_in_queue' )
738+ expect ( queue_time ) . to be_within ( 10 ) . of ( 30 )
739+ end
736740 end
737741 end
738742
0 commit comments