Skip to content

[#151] Fix the batch test race and return pooled connectors in UseCase3 tests - #153

Open
vharseko wants to merge 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:issue151-batch-test-race
Open

vharseko wants to merge 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:issue151-batch-test-race

Conversation

@vharseko

@vharseko vharseko commented Oct 5, 2026

Copy link
Copy Markdown
Member

Fixes #151

Problem

LocalConnectorInfoManagerTests.testBatchUseCase3Failure checked that there were no results right after executeBatch(). The UseCase3 test connector delivers results to the observer from its own thread, so the first onNext() can run before that check. Stress-running the test 300 times on master gave 6 failures with expected [0] but found [1], the error reported in #151.

Fixing it turned up two more problems:

  • Pooled connectors were never returned. Each Subscription that executeBatch()/queryBatch() return holds a pooled connector until it is closed. The tests never closed theirs. A single run hides this, but repeated runs exhaust the pool and hang in ObjectPool.borrowObject().
  • NPE on close. Once the batch has finished, the connector may return null from queryBatch(); TstConnector does. SubscriptionImpl wraps that null. Its getReturnValue() already handled null, but close() and isUnsubscribed() threw an NPE.

Change

  • LocalConnectorInfoManagerTests:
    • testBatchUseCase3Failure no longer checks the transient state. It waits up to 3 s for hasError instead of a fixed Thread.sleep(500), the same approach Stabilize release-maven by removing race-prone assertion in testBatchUseCase3 #93 took for testBatchUseCase3. hasError is set after the result is added to the list, so both results are in place when the wait ends.
    • Both UseCase3 tests close their subscriptions in finally. testBatchUseCase3 keeps the queryBatch() subscription in its own variable instead of overwriting the executeBatch() one.
  • SubscriptionImpl:
    • In the executeBatch() and queryBatch() wrappers, close() and isUnsubscribed() now accept a null subscription. So does getReturnValue() of executeBatch().
    • doRelease() still runs first, so the reference counter is always released.

Contrary to what #151 says, testBatchUseCase2 and testBatchUseCase2Failure are not affected. In UseCase2 the results reach the observer only through queryBatch(), which the test thread itself calls.

Testing

  • Stress run, 300 invocations each of testBatchUseCase3 and testBatchUseCase3Failure: 600/600 pass in 65 s, with no hang.
    • Before this change: the old assertions failed 6/300.
    • With the leak still present, the run hung after about 10 invocations.
  • Full test runs pass for connector-framework (197), connector-test-common (5), connector-framework-internal (509, 2 skipped as before), connector-framework-rpc (21) and connector-framework-server (32).

…connectors in UseCase3 tests

testBatchUseCase3Failure asserted zero results right after executeBatch(),
but the UseCase3 test connector delivers results from its own thread, so
the first onNext() could already have run. Drop the transient checks and
wait up to 3 s for hasError instead of a fixed 500 ms sleep, as OpenIdentityPlatform#93 did
for testBatchUseCase3.

Both UseCase3 tests now close their subscriptions: each one holds a pooled
connector until it is closed, so repeated runs exhausted the pool and
hung in borrowObject().

Closing the queryBatch subscription of a finished batch threw an NPE,
because SubscriptionImpl wrapped the null subscription returned by the
connector. Make close() and isUnsubscribed() of the executeBatch and
queryBatch wrappers null-safe, as getReturnValue() of queryBatch already
was.

Fixes OpenIdentityPlatform#151
@vharseko vharseko added bug Something isn't working java Pull requests that update java code tests Test additions or fixes framework OpenICF-java-framework concurrency Races, locking and thread-safety fixes labels Oct 5, 2026
@vharseko
vharseko requested a review from maximthomas October 5, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working concurrency Races, locking and thread-safety fixes framework OpenICF-java-framework java Pull requests that update java code tests Test additions or fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky LocalConnectorInfoManagerTests.testBatchUseCase3Failure: asserts no batch results right after executeBatch

1 participant