Skip to content

Commit f291b96

Browse files
fix: properly mock time in ruby ci tests
1 parent 25fd621 commit f291b96

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

test/docker_engine_ruby/client_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,21 @@ def test_client_retry_after_seconds
161161
end
162162

163163
def test_client_retry_after_date
164+
time_now = Time.now
165+
164166
stub_request(:get, "http://localhost/containers/json").to_return_json(
165167
status: 500,
166-
headers: {"retry-after" => (Time.now + 10).httpdate},
168+
headers: {"retry-after" => (time_now + 10).httpdate},
167169
body: {}
168170
)
169171

170172
docker = DockerEngineRuby::Client.new(base_url: "http://localhost", max_retries: 1)
171173

174+
Thread.current.thread_variable_set(:time_now, time_now)
172175
assert_raises(DockerEngineRuby::Errors::InternalServerError) do
173-
Thread.current.thread_variable_set(:time_now, Time.now)
174176
docker.containers.list
175-
Thread.current.thread_variable_set(:time_now, nil)
176177
end
178+
Thread.current.thread_variable_set(:time_now, nil)
177179

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

0 commit comments

Comments
 (0)