Skip to content

Commit

Permalink
HSEARCH-4316 Prioritize displaying unexpected calls when expectations…
Browse files Browse the repository at this point in the history
… are not met in BackendMock

Unexpected calls are often the right place to start to debug problems,
so we might as well display them first.
  • Loading branch information
yrodiere committed Nov 30, 2021
1 parent 752e1ee commit 67e6bc4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Expand Up @@ -217,14 +217,16 @@ private AssertionError createFailure(String message) {
throw new IllegalStateException( "This should not happen" );
}

public synchronized void verifyExpectationsMet() {
public synchronized void verifyNoUnexpectedCall() {
if ( lastVerifyFailure != null ) {
Fail.fail(
"A verify error occurred during the test: " + lastVerifyFailure.getMessage(),
lastVerifyFailure
);
}
}

public synchronized void verifyExpectationsMet() {
List<C> remaining = new ArrayList<>();
remaining.addAll( callsExpectedInOrder );
remaining.addAll( callsExpectedOutOfOrder );
Expand Down
Expand Up @@ -205,6 +205,20 @@ void verifyExpectationsMet() {
// we also report the additional ones as suppressed exceptions.
try ( Closer<RuntimeException> closer = new Closer<>() ) {
// We don't check anything for the various behaviors (createBackendBehaviors, ...): they are ignored if they are not executed.

// First, we check that there weren't any unexpected calls:
// those are the most useful to debug problems.
closer.pushAll( CallQueue::verifyNoUnexpectedCall, schemaDefinitionCalls.values() );
closer.pushAll( CallQueue::verifyNoUnexpectedCall, indexScaleWorkCalls.values() );
closer.pushAll( CallQueue::verifyNoUnexpectedCall, schemaManagementWorkCall.values() );
closer.pushAll( CallQueue::verifyNoUnexpectedCall, documentWorkCreateCalls.values() );
closer.pushAll( CallQueue::verifyNoUnexpectedCall, documentWorkDiscardCalls.values() );
closer.pushAll( CallQueue::verifyNoUnexpectedCall, documentWorkExecuteCalls.values() );
closer.pushAll( CallQueue::verifyNoUnexpectedCall,
searchCalls, countCalls,
scrollCalls, closeScrollCalls, nextScrollCalls );

// Then, we check that whatever we *were* expecting actually happened.
closer.pushAll( CallQueue::verifyExpectationsMet, schemaDefinitionCalls.values() );
closer.pushAll( CallQueue::verifyExpectationsMet, indexScaleWorkCalls.values() );
closer.pushAll( CallQueue::verifyExpectationsMet, schemaManagementWorkCall.values() );
Expand All @@ -221,7 +235,7 @@ void verifyExpectationsMet() {
);
closer.pushAll( CallQueue::verifyExpectationsMet,
searchCalls, countCalls,
scrollCalls, closeScrollCalls, nextScrollCalls, closeScrollCalls );
scrollCalls, closeScrollCalls, nextScrollCalls );
}

if ( indexingWorkExpectations.allowDuplicateIndexing() ) {
Expand Down

0 comments on commit 67e6bc4

Please sign in to comment.