Skip to content

Commit

Permalink
test: Add workaround for windows test failure (#1751)
Browse files Browse the repository at this point in the history
We have to instantiate the processor outside of the stub so that the
stub can be applied to the processor, but the method we're stubbing
runs on initialization, so we sometimes run out of expectations.

If we explicitly set 'OTEL_RUBY_BLRP_START_THREAD_ON_BOOT' to 'false'
for the 'removes the older log records from the batch if full' test, the
stubbed `work` method will not run outside of the stub block.

Co-authored-by: Tanna McClure <[email protected]>
  • Loading branch information
kaylareopelle and tannalynn authored Nov 15, 2024
1 parent 555b062 commit be01344
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,23 @@ def to_log_record_data
end

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)
# Windows intermittently fails if we don't set this
OpenTelemetry::TestHelpers.with_env('OTEL_RUBY_BLRP_START_THREAD_ON_BOOT' => 'false') do
processor = BatchLogRecordProcessor.new(TestExporter.new, max_queue_size: 1, max_export_batch_size: 1)

# 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
# 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(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, older_log_record)
assert_includes(records, newest_log_record)
refute_includes(records, older_log_record)
end
end
end

Expand Down

0 comments on commit be01344

Please sign in to comment.