Skip to content

Commit 3d3021f

Browse files
fix: properly mock time in ruby ci tests
1 parent 358c634 commit 3d3021f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

test/brand_dev/client_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,21 @@ def test_client_retry_after_seconds
100100
end
101101

102102
def test_client_retry_after_date
103+
time_now = Time.now
104+
103105
stub_request(:get, "http://localhost/brand/retrieve").to_return_json(
104106
status: 500,
105-
headers: {"retry-after" => (Time.now + 10).httpdate},
107+
headers: {"retry-after" => (time_now + 10).httpdate},
106108
body: {}
107109
)
108110

109111
brand_dev = BrandDev::Client.new(base_url: "http://localhost", api_key: "My API Key", max_retries: 1)
110112

113+
Thread.current.thread_variable_set(:time_now, time_now)
111114
assert_raises(BrandDev::Errors::InternalServerError) do
112-
Thread.current.thread_variable_set(:time_now, Time.now)
113115
brand_dev.brand.retrieve(domain: "domain")
114-
Thread.current.thread_variable_set(:time_now, nil)
115116
end
117+
Thread.current.thread_variable_set(:time_now, nil)
116118

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

0 commit comments

Comments
 (0)