Skip to content

fix(test): fix TChannel span test flakiness by awaiting async spans and explicitly setting worker tracer - #1078

Closed
shijiesheng with Copilot wants to merge 1 commit into
masterfrom
copilot/check-failing-unit-test
Closed

fix(test): fix TChannel span test flakiness by awaiting async spans and explicitly setting worker tracer#1078
shijiesheng with Copilot wants to merge 1 commit into
masterfrom
copilot/check-failing-unit-test

Conversation

Copilot AI commented Aug 14, 2026

Copy link
Copy Markdown

Tests testStartWorkflowTchannel and testSignalWithStartWorkflowTchannel were failing because (1) TChannel finishes client spans asynchronously in response callbacks — spans may not be visible the moment the calling thread resumes — and (2) the worker's tracer was not reliably inheriting mockTracer from service options due to instanceof NoopTracer check fragility from transitive opentracing-noop version conflicts.

What changed?

  • FakeWorkflowServiceRule: Added awaitSpan(operationName) — polls finishedSpans() up to 5s to handle TChannel's async span completion in unit tests
  • WorkflowClientInternalTest: Switched assertions to use awaitSpan instead of reading finishedSpans() directly
  • StartWorkflowTest (docker integration tests):
    • Added awaitSpans() with 30s timeout in testStartWorkflowHelper and testSignalWithStartWorkflowHelper to handle async span visibility
    • Explicitly pass mockTracer to WorkerOptions when shouldPropagate=true rather than relying on Worker.java's instanceof NoopTracer fallback, which can silently fail when classpath contains mismatched opentracing-noop versions
// Before: relied on Worker.java's instanceof NoopTracer fallback
worker = workerFactory.newWorker(TASK_LIST, WorkerOptions.newBuilder().build());

// After: explicitly propagate mockTracer when tracing is expected
WorkerOptions workerOptions = shouldPropagate
    ? WorkerOptions.newBuilder().setTracer(mockTracer).build()
    : WorkerOptions.newBuilder().build();
worker = workerFactory.newWorker(TASK_LIST, workerOptions);

Why?

TChannel spans are finalized in a response callback thread, not the caller thread. Tests that read finishedSpans() synchronously after a TChannel call can see incomplete span state. Additionally, Worker.java's automatic tracer propagation via instanceof NoopTracer is fragile under dependency version conflicts between tchannel-core's transitive opentracing and the test's opentracing-mock.

How did you test it?

Changes validated against the CI test run that exposed the failures (job 94609211566).

Potential risks

None — test-only changes.

Release notes

None.

Documentation Changes

None.

Copilot AI changed the title [WIP] Investigate failing unit test in cadence-java-client fix(test): fix TChannel span test flakiness by awaiting async spans and explicitly setting worker tracer Aug 14, 2026
Copilot AI requested a review from shijiesheng August 14, 2026 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants