@@ -80,16 +80,8 @@ def activate_ci!(settings)
80
80
# startup logs are useless for test visibility and create noise
81
81
settings . diagnostics . startup_logs . enabled = false
82
82
83
- # When timecop is present, Time.now is mocked and .now_without_mock_time is added on Time to
84
- # get the current time without the mock.
85
- if timecop?
86
- settings . time_now_provider = -> do
87
- Time . now_without_mock_time
88
- rescue NoMethodError
89
- # fallback to normal Time.now if Time.now_without_mock_time is not defined for any reason
90
- Time . now
91
- end
92
- end
83
+ # timecop configuration
84
+ configure_time_providers ( settings )
93
85
94
86
# Configure Datadog::Tracing module
95
87
@@ -182,7 +174,6 @@ def build_test_visibility_api(settings)
182
174
# Tests are running without CI visibility enabled
183
175
settings . ci . enabled = false
184
176
end
185
-
186
177
else
187
178
Datadog . logger . debug ( "CI visibility configured to use agent transport via EVP proxy" )
188
179
@@ -299,6 +290,29 @@ def configure_telemetry(settings)
299
290
end
300
291
end
301
292
293
+ # When timecop is present:
294
+ # - Time.now is mocked and .now_without_mock_time is added on Time to get the current time without the mock.
295
+ # - Process.clock_gettime is mocked and .clock_gettime_without_mock is added on Process to get the monotonic time without the mock.
296
+ def configure_time_providers ( settings )
297
+ return unless timecop?
298
+
299
+ settings . time_now_provider = -> do
300
+ Time . now_without_mock_time
301
+ rescue NoMethodError
302
+ # fallback to normal Time.now if Time.now_without_mock_time is not defined for any reason
303
+ Time . now
304
+ end
305
+
306
+ if defined? ( Process . clock_gettime_without_mock )
307
+ settings . get_time_provider = -> ( unit = :float_second ) do
308
+ ::Process . clock_gettime_without_mock ( ::Process ::CLOCK_MONOTONIC , unit )
309
+ rescue NoMethodError
310
+ # fallback to normal Process.clock_gettime if Process.clock_gettime_without_mock is not defined for any reason
311
+ Process . clock_gettime ( ::Process ::CLOCK_MONOTONIC , unit )
312
+ end
313
+ end
314
+ end
315
+
302
316
def timecop?
303
317
Gem . loaded_specs . key? ( "timecop" ) || !!defined? ( Timecop )
304
318
end
0 commit comments