From be01344514c533a1760a507b8d6133acffda22af Mon Sep 17 00:00:00 2001 From: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> Date: Fri, 15 Nov 2024 13:05:15 -0800 Subject: [PATCH] test: Add workaround for windows test failure (#1751) 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 --- .../export/batch_log_record_processor_test.rb | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/logs_sdk/test/opentelemetry/sdk/logs/export/batch_log_record_processor_test.rb b/logs_sdk/test/opentelemetry/sdk/logs/export/batch_log_record_processor_test.rb index a7ed0c362..cff2b718d 100644 --- a/logs_sdk/test/opentelemetry/sdk/logs/export/batch_log_record_processor_test.rb +++ b/logs_sdk/test/opentelemetry/sdk/logs/export/batch_log_record_processor_test.rb @@ -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