Skip to content

Commit 8f0a0a9

Browse files
fix: properly mock time in ruby ci tests
1 parent 650aa0f commit 8f0a0a9

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

test/imagekitio/client_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,11 @@ def test_client_retry_after_seconds
136136
end
137137

138138
def test_client_retry_after_date
139+
time_now = Time.now
140+
139141
stub_request(:post, "http://localhost/api/v1/files/upload").to_return_json(
140142
status: 500,
141-
headers: {"retry-after" => (Time.now + 10).httpdate},
143+
headers: {"retry-after" => (time_now + 10).httpdate},
142144
body: {}
143145
)
144146

@@ -150,11 +152,11 @@ def test_client_retry_after_date
150152
max_retries: 1
151153
)
152154

155+
Thread.current.thread_variable_set(:time_now, time_now)
153156
assert_raises(Imagekitio::Errors::InternalServerError) do
154-
Thread.current.thread_variable_set(:time_now, Time.now)
155157
image_kit.files.upload(file: Pathname(__FILE__), file_name: "fileName")
156-
Thread.current.thread_variable_set(:time_now, nil)
157158
end
159+
Thread.current.thread_variable_set(:time_now, nil)
158160

159161
assert_requested(:any, /./, times: 2)
160162
assert_in_delta(10, Thread.current.thread_variable_get(:mock_sleep).last, 1.0)

0 commit comments

Comments
 (0)