Skip to content

Commit

Permalink
test: Fix intermittent test failures (#1730)
Browse files Browse the repository at this point in the history
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 method to do nothing.

Co-authored-by: Tanna McClure <[email protected]>
Co-authored-by: Matthew Wear <[email protected]>
  • Loading branch information
3 people authored Oct 1, 2024
1 parent cdce3cc commit 3c356fc
Showing 1 changed file with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,19 @@ def to_log_record_data
it 'removes the older log records from the batch if full' do
processor = BatchLogRecordProcessor.new(TestExporter.new, max_queue_size: 1, max_export_batch_size: 1)

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

processor.on_emit(older_log_record, mock_context)
processor.on_emit(newer_log_record, mock_context)
processor.on_emit(newest_log_record, mock_context)
processor.on_emit(older_log_record, mock_context)
processor.on_emit(newest_log_record, mock_context)

records = processor.instance_variable_get(:@log_records)
records = processor.instance_variable_get(:@log_records)

assert_includes(records, newest_log_record)
refute_includes(records, newer_log_record)
refute_includes(records, older_log_record)
assert_includes(records, newest_log_record)
refute_includes(records, older_log_record)
end
end

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

it 'reports export failures' do
mock_logger = Minitest::Mock.new
mock_logger.expect(:error, nil, [/Unable to export/])
mock_logger.expect(:error, nil, [/Result code: 1/])
mock_logger.expect(:error, nil, [/unexpected error in .*\#export_batch/])

OpenTelemetry.stub(:logger, mock_logger) do
log_records = [TestLogRecord.new, TestLogRecord.new, TestLogRecord.new, TestLogRecord.new]
log_records.each { |log_record| processor.on_emit(log_record, mock_context) }
processor.shutdown
end
# skip the work method's behavior, we rely on shutdown to get us to the failures
processor.stub(:work, nil) do
mock_logger = Minitest::Mock.new
mock_logger.expect(:error, nil, [/Unable to export/])
mock_logger.expect(:error, nil, [/Result code: 1/])
mock_logger.expect(:error, nil, [/unexpected error in .*\#export_batch/])

OpenTelemetry.stub(:logger, mock_logger) do
log_records = [TestLogRecord.new, TestLogRecord.new, TestLogRecord.new, TestLogRecord.new]
log_records.each { |log_record| processor.on_emit(log_record, mock_context) }
processor.shutdown
end

mock_logger.verify
mock_logger.verify
end
end
end

Expand Down

0 comments on commit 3c356fc

Please sign in to comment.