Skip to content

Commit 6ba0e89

Browse files
fix: properly mock time in ruby ci tests
1 parent f02a608 commit 6ba0e89

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

test/stagehand/client_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,11 @@ def test_client_retry_after_seconds
133133
end
134134

135135
def test_client_retry_after_date
136+
time_now = Time.now
137+
136138
stub_request(:post, "http://localhost/v1/sessions/start").to_return_json(
137139
status: 500,
138-
headers: {"retry-after" => (Time.now + 10).httpdate},
140+
headers: {"retry-after" => (time_now + 10).httpdate},
139141
body: {}
140142
)
141143

@@ -148,11 +150,11 @@ def test_client_retry_after_date
148150
max_retries: 1
149151
)
150152

153+
Thread.current.thread_variable_set(:time_now, time_now)
151154
assert_raises(Stagehand::Errors::InternalServerError) do
152-
Thread.current.thread_variable_set(:time_now, Time.now)
153155
stagehand.sessions.start(model_name: "openai/gpt-4o")
154-
Thread.current.thread_variable_set(:time_now, nil)
155156
end
157+
Thread.current.thread_variable_set(:time_now, nil)
156158

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

0 commit comments

Comments
 (0)