open-telemetry / opentelemetry-python

OpenTelemetry Python API and SDK
https://opentelemetry.io
Apache License 2.0
1.67k stars 569 forks source link

Flaky test in opentelemetry-sdk #3911

Closed xrmx closed 2 weeks ago

xrmx commented 1 month ago

Describe your environment

Flaky test in CI, we are asserting that the time will be greater than 500 but in this run it was less than that. We could probably use assertAlmostEqual instead.

______ TestBatchSpanProcessor.test_batch_span_processor_scheduled_delay _______

self = <tests.trace.export.test_export.TestBatchSpanProcessor testMethod=test_batch_span_processor_scheduled_delay>

    def test_batch_span_processor_scheduled_delay(self):
        """Test that spans are exported each schedule_delay_millis"""
        spans_names_list = []

        export_event = threading.Event()
        my_exporter = MySpanExporter(
            destination=spans_names_list, export_event=export_event
        )
        start_time = time.time()
        span_processor = export.BatchSpanProcessor(
            my_exporter,
            schedule_delay_millis=500,
        )

        # create single span
        resource = Resource.create({})
        _create_start_and_end_span("foo", span_processor, resource)

        self.assertTrue(export_event.wait(2))
        export_time = time.time()
        self.assertEqual(len(spans_names_list), 1)
>       self.assertGreaterEqual((export_time - start_time) * 1e3, 500)
E       AssertionError: 499.9737739562988 not greater than or equal to 500

Steps to reproduce

tox -e pypy3-opentelemetry-sdk

What is the expected behavior?

Test will pass everytime

What is the actual behavior?

Test is flaky

Additional context