diff --git a/test/api/opentelemetry_inspan_test.rb b/test/api/opentelemetry_inspan_test.rb index 1e9d8bfb..792e87b9 100644 --- a/test/api/opentelemetry_inspan_test.rb +++ b/test/api/opentelemetry_inspan_test.rb @@ -3,15 +3,17 @@ require 'minitest_helper' require './lib/solarwinds_apm/api' +# act -j unit_test --container-architecture linux/arm64 -s SW_APM_SERVICE_KEY=your_key +# describe 'SolarWinds Set Transaction Name Test' do before do - @op = -> { 1.times {[9, 6, 12, 2, 7, 1, 9, 3, 4, 14, 5, 8].sort} } + @op = -> { 10.times {[9, 6, 12, 2, 7, 1, 9, 3, 4, 14, 5, 8].sort} } end it 'test_in_span_wrapper_from_solarwinds_apm' do - in_memory_exporter = CustomInMemorySpanExporter.new + in_memory_exporter = ::OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new OpenTelemetry::SDK.configure do |c| c.service_name = 'test_in_span_wrapper_from_solarwinds_apm' c.add_span_processor( @@ -23,7 +25,7 @@ @op.call end - finished_spans = in_memory_exporter.finished_spans + finished_spans = extract_span(in_memory_exporter) _(finished_spans.first.name).must_equal 'custom_span' @@ -32,7 +34,7 @@ it 'test_in_span_wrapper_from_solarwinds_apm_with_span' do - in_memory_exporter = CustomInMemorySpanExporter.new + in_memory_exporter = ::OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new OpenTelemetry::SDK.configure do |c| c.service_name = 'test_in_span_wrapper_from_solarwinds_apm_with_span' c.add_span_processor( @@ -45,7 +47,7 @@ @op.call end - finished_spans = in_memory_exporter.finished_spans + finished_spans = extract_span(in_memory_exporter) _(finished_spans.first.name).must_equal 'custom_span' _(finished_spans.first.attributes['test_attribute']).must_equal 'attribute_1' @@ -55,7 +57,7 @@ it 'test_in_span_wrapper_from_solarwinds_apm_without_block' do - in_memory_exporter = CustomInMemorySpanExporter.new + in_memory_exporter = ::OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new OpenTelemetry::SDK.configure do |c| c.service_name = 'test_in_span_wrapper_from_solarwinds_apm' c.add_span_processor( @@ -65,7 +67,7 @@ SolarWindsAPM::API.in_span('custom_span') - finished_spans = in_memory_exporter.finished_spans + finished_spans = extract_span(in_memory_exporter) _(finished_spans.size).must_equal 0 in_memory_exporter.shutdown diff --git a/test/minitest_helper.rb b/test/minitest_helper.rb index 8099c9c7..d5d406ca 100644 --- a/test/minitest_helper.rb +++ b/test/minitest_helper.rb @@ -186,6 +186,27 @@ def export(span_datas) end end + +## +# extract_span +# +# get finished_span from exporter that overcome time issue +# +def extract_span(exporter) + finished_spans = [] + retry_count = 5 + while finished_spans.size == 0 + + break if retry_count > 5 + + finished_spans = exporter.finished_spans + retry_count += 1 + sleep retry_count + end + + finished_spans +end + ## # create_span_data #