Skip to content

test(sdk): fix flaky BatchProcessor shutdown test (#5663) - #5675

Merged
lzchen merged 2 commits into
open-telemetry:mainfrom
Anurag-M1:fix-5663-flaky-batch-processor-shutdown-test
Sep 21, 2026
Merged

lzchen merged 2 commits into
open-telemetry:mainfrom
Anurag-M1:fix-5663-flaky-batch-processor-shutdown-test

Conversation

@Anurag-M1

Copy link
Copy Markdown
Contributor

Description

Fixes #5663.

In test_shutdown_allows_1_export_to_finish (opentelemetry-sdk/tests/shared_internal/test_batch_processor.py), processor.shutdown() interrupts the in-progress export via exporter.shutdown(). Depending on thread scheduling, especially on Windows and PyPy runners, the worker thread can terminate before shutdown() returns. This caused the intermediate assertion assert processor._batch_processor._worker_thread.is_alive() is True to fail intermittently in CI.

Changes

  • Replace wall-clock time.time() with time.monotonic() for elapsed time measurement.
  • Remove the race-prone intermediate is_alive() is True assertion immediately following shutdown().
  • Add deterministic processor._batch_processor._worker_thread.join(timeout=1) before asserting eventual termination (is_alive() is False), rather than relying on an arbitrary time.sleep(0.1).
  • Keep all remaining assertions (after - before < 3.3, exporter.sleep_interrupted is True, and 2 == exporter.num_export_calls) intact.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • Followed the style guidelines of this project
  • Ran unit tests locally (pytest opentelemetry-sdk/tests/shared_internal/test_batch_processor.py)
  • Ran linting checks (ruff check, ruff format --check)
  • Change is isolated to test reliability and introduces no functional regression

In test_shutdown_allows_1_export_to_finish, processor.shutdown()
interrupts the in-progress export via exporter.shutdown(). Depending on
thread scheduling, particularly on Windows and PyPy runners, the worker
thread can terminate before shutdown() returns, causing the intermediate
assertion assert worker_thread.is_alive() is True to fail intermittently.

Fix this by:
- Using time.monotonic() instead of time.time() for elapsed time.
- Removing the unstable intermediate is_alive() is True check.
- Waiting deterministically with worker_thread.join(timeout=1) before
  asserting that the worker thread has terminated.

Fixes open-telemetry#5663

Assisted-by: Gemini 3.8 Flash
@Anurag-M1
Anurag-M1 requested a review from a team as a code owner September 19, 2026 06:00
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: Anurag-M1 / name: Anurag Singh (43b08a5)

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-09-21 15:23 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused test-only changes correctly address the reported scheduling race without altering production behavior.

Review effort: Balanced
Findings: None

What changed in this PR

Improves reliability of the SDK BatchProcessor shutdown test.

Changes:

  • Uses monotonic elapsed-time measurement.
  • Removes a race-prone intermediate assertion.
  • Replaces fixed sleep with a bounded worker-thread join.
File Description
opentelemetry-sdk/​tests/​shared_internal/​test_batch_processor.py Makes shutdown verification resilient to thread scheduling differences.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest Sep 21, 2026
@lzchen lzchen added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Sep 21, 2026
@lzchen
lzchen added this pull request to the merge queue Sep 21, 2026
Merged via the queue into open-telemetry:main with commit b1f499b Sep 21, 2026
575 of 576 checks passed
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Python PR digest Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Skip Changelog PRs that do not require a CHANGELOG.md entry

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Flaky BatchProcessor shutdown test fails on Windows/PyPy

4 participants