Skip to content

Commit 51cc6b9

Browse files
jnunemakerclaude
andcommitted
fix: freeze time in logstash formatter test to prevent flaky failures
The test was comparing timestamps captured at different moments, causing intermittent failures when a second boundary was crossed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 55ec76e commit 51cc6b9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

spec/httparty/logger/logstash_formatter_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
let(:path) { 'http://my.domain.com/my_path' }
88
let(:logger_double) { double('Logger') }
99
let(:request_double) { double('Request', http_method: Net::HTTP::Get, path: "#{path}") }
10-
let(:request_time) { Time.new.strftime("%Y-%m-%d %H:%M:%S %z") }
10+
let(:frozen_time) { Time.new(2024, 1, 1, 12, 0, 0, "+00:00") }
11+
let(:request_time) { frozen_time.strftime("%Y-%m-%d %H:%M:%S %z") }
1112
let(:log_message) do
1213
{
1314
'@timestamp' => request_time,
@@ -25,6 +26,7 @@
2526
subject { described_class.new(logger_double, severity) }
2627

2728
before do
29+
allow(Time).to receive(:now).and_return(frozen_time)
2830
expect(logger_double).to receive(:info).with(log_message)
2931
end
3032

0 commit comments

Comments
 (0)