Skip to content

Commit a3467ce

Browse files
test: Fix intermittent test failures
Some tests in BatchLogRecordProcessor had timing issues due to the work method. Since we don't rely on that method for these tests, stub the work operation to do nothing. Co-authored-by: Tanna McClure <[email protected]>
1 parent d2318b0 commit a3467ce

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

logs_sdk/test/opentelemetry/sdk/logs/export/batch_log_record_processor_test.rb

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,19 @@ def to_log_record_data
188188
it 'removes the older log records from the batch if full' do
189189
processor = BatchLogRecordProcessor.new(TestExporter.new, max_queue_size: 1, max_export_batch_size: 1)
190190

191-
older_log_record = TestLogRecord.new
192-
newer_log_record = TestLogRecord.new
193-
newest_log_record = TestLogRecord.new
191+
# Don't actually try to export, we're looking at the log records array
192+
processor.stub(:work, nil) do
193+
older_log_record = TestLogRecord.new
194+
newest_log_record = TestLogRecord.new
194195

195-
processor.on_emit(older_log_record, mock_context)
196-
processor.on_emit(newer_log_record, mock_context)
197-
processor.on_emit(newest_log_record, mock_context)
196+
processor.on_emit(older_log_record, mock_context)
197+
processor.on_emit(newest_log_record, mock_context)
198198

199-
records = processor.instance_variable_get(:@log_records)
199+
records = processor.instance_variable_get(:@log_records)
200200

201-
assert_includes(records, newest_log_record)
202-
refute_includes(records, newer_log_record)
203-
refute_includes(records, older_log_record)
201+
assert_includes(records, newest_log_record)
202+
refute_includes(records, older_log_record)
203+
end
204204
end
205205

206206
it 'logs a warning if a log record was emitted after the buffer is full' do
@@ -469,18 +469,21 @@ def shutdown(timeout: nil)
469469
let(:processor) { BatchLogRecordProcessor.new(exporter) }
470470

471471
it 'reports export failures' do
472-
mock_logger = Minitest::Mock.new
473-
mock_logger.expect(:error, nil, [/Unable to export/])
474-
mock_logger.expect(:error, nil, [/Result code: 1/])
475-
mock_logger.expect(:error, nil, [/unexpected error in .*\#export_batch/])
476-
477-
OpenTelemetry.stub(:logger, mock_logger) do
478-
log_records = [TestLogRecord.new, TestLogRecord.new, TestLogRecord.new, TestLogRecord.new]
479-
log_records.each { |log_record| processor.on_emit(log_record, mock_context) }
480-
processor.shutdown
481-
end
472+
# skip the work method's behavior, we rely on shutdown to get us to the failures
473+
processor.stub(:work, nil) do
474+
mock_logger = Minitest::Mock.new
475+
mock_logger.expect(:error, nil, [/Unable to export/])
476+
mock_logger.expect(:error, nil, [/Result code: 1/])
477+
mock_logger.expect(:error, nil, [/unexpected error in .*\#export_batch/])
478+
479+
OpenTelemetry.stub(:logger, mock_logger) do
480+
log_records = [TestLogRecord.new, TestLogRecord.new, TestLogRecord.new, TestLogRecord.new]
481+
log_records.each { |log_record| processor.on_emit(log_record, mock_context) }
482+
processor.shutdown
483+
end
482484

483-
mock_logger.verify
485+
mock_logger.verify
486+
end
484487
end
485488
end
486489

0 commit comments

Comments
 (0)