oci-java-sdk icon indicating copy to clipboard operation
oci-java-sdk copied to clipboard

fix: stablize flaky test in bmc-aispeech-realtime

Open lycoris106 opened this issue 2 months ago • 2 comments

Description

This PR fixes some flaky tests found with NonDex, which explores non-determinism in tests. These tests can fail under different JVMs, hash seeds, etc.

The flaky tests:

  • RealtimeSpeechClientTest.testOnConnectAndClose

Root Cause

In the test testOnConnectAndClose, the assertion assumes a fixed order of fields in the json string. However, JSON serialization depends on non-deterministic map iteration order and can place testKey before or after uri:

expected:<...ENT_ID","headers":{"[testKey":"testValue","uri":"wss://test-endpoint.com/ws/transcribe/stream]"}}> but was:<...ENT_ID","headers":{"[uri":"wss://test-endpoint.com/ws/transcribe/stream","testKey":"testValue]"}}>

Fix

We use a safer way to compare jsons, by parsing them into jackson's JsonNodes.

Failure Reproduction

  • Java version:
    openjdk 21.0.8 2025-07-15
    OpenJDK Runtime Environment (build 21.0.8+9-Ubuntu-0ubuntu124.04.1)
    OpenJDK 64-Bit Server VM (build 21.0.8+9-Ubuntu-0ubuntu124.04.1, mixed mode, sharing)
    
  • OS version: Ubuntu 24.04.3 LTS

Build with the main branch and run tests with NonDex to observe the failure, for example:

mvn edu.illinois:nondex-maven-plugin:2.2.1:nondex -pl bmc-objectstorage/bmc-objectstorage-extensions \
    -Dtest=RealtimeSpeechClientTest -DnondexRuns=10 \
    -Djacoco.skip -Drat.skip -Dpmd.skip -Denforcer.skip

Notes

  • This fix only modifies test code but no production code

lycoris106 avatar Dec 04 '25 03:12 lycoris106