Skip to content

Commit 85b0456

Browse files
matchers: containExactly early stop when failing (#1573)
1 parent 14ba1e2 commit 85b0456

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

webtau-core/src/main/java/org/testingisdocumenting/webtau/expectation/contain/ContainExactlyMatcher.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ private boolean matches(CompareToComparator comparator, ValuePath actualPath, Ob
159159
CompareToHandler compareToHandlerToUse = null;
160160

161161
Iterator<ValuePathWithValue<Object>> expectedIt = expectedCopy.iterator();
162-
while (expectedIt.hasNext()) {
162+
int notFoundCount = 0;
163+
while (expectedIt.hasNext() && notFoundCount < 10) {
163164
ValuePathWithValue<Object> expected = expectedIt.next();
164165
Iterator<ValuePathWithValue<Object>> actualIt = actualCopy.iterator();
165166

@@ -195,6 +196,7 @@ private boolean matches(CompareToComparator comparator, ValuePath actualPath, Ob
195196
}
196197

197198
if (!found && collectSuspects) {
199+
notFoundCount++;
198200
notEqualMessagesByExpectedPath.put(expected.getPath(),
199201
compareToResults.stream().map(CompareToResult::getNotEqualMessages).toList());
200202

@@ -209,7 +211,13 @@ private boolean matches(CompareToComparator comparator, ValuePath actualPath, Ob
209211
private ValuePathLazyMessageList extractPotentialNotEqualMessages() {
210212
List<ValuePath> actualPaths = actualCopy.stream().map(ValuePathWithValue::getPath).toList();
211213
ValuePathLazyMessageList notEqualCandidateMessages = new ValuePathLazyMessageList();
214+
int idx = 0;
212215
for (ValuePathWithValue<Object> expectedWithPath : expectedCopy) {
216+
idx++;
217+
if (idx > 10) {
218+
break;
219+
}
220+
213221
List<ValuePathLazyMessageList> notEqualMessageBatches = notEqualMessagesByExpectedPath.get(expectedWithPath.getPath());
214222
if (notEqualMessageBatches == null) {
215223
continue;

webtau-core/src/main/java/org/testingisdocumenting/webtau/expectation/equality/ValuePathLazyMessageList.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public ValuePathMessage first() {
6161
}
6262

6363
public void addAll(Iterable<ValuePathMessage> messages) {
64+
if (size >= SIZE_LIMIT) {
65+
return;
66+
}
67+
6468
if (messages == null) {
6569
return;
6670
}
@@ -71,7 +75,7 @@ public void addAll(Iterable<ValuePathMessage> messages) {
7175
public void merge(ValuePathLazyMessageList list) {
7276
if (list.size == 1) {
7377
add(list.first());
74-
} else {
78+
} else if (size < SIZE_LIMIT) {
7579
for (ValuePathMessage message : list) {
7680
add(message);
7781
}

0 commit comments

Comments
 (0)