Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility for asserting listeners are completed #109325

Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
984e2fd
Add utility for asserting listeners are completed
nicktindall Jun 4, 2024
1b54b82
Fix formatting
nicktindall Jun 4, 2024
c94c829
Remove unnecessary escaping
nicktindall Jun 4, 2024
99d0e16
Update server/src/main/java/org/elasticsearch/action/ActionListenerIm…
nicktindall Jun 4, 2024
323b6f6
Remove/minimise assertBusy blocks
nicktindall Jun 4, 2024
a88ce9f
Remove unnecessary System.gc()
nicktindall Jun 4, 2024
1e84c2b
Merge branch 'main' into fix/108123_add_utility_assert_listeners_comp…
nicktindall Jun 5, 2024
bf99ff0
Only test for a single call to onResponse OR onFailure
nicktindall Jun 5, 2024
9171a55
Merge branch 'main' into fix/108123_add_utility_assert_listeners_comp…
nicktindall Jun 6, 2024
b90f16b
Use LeakTracker to detect non-completed ActionListeners
nicktindall Jun 9, 2024
4f0e438
Merge branch 'main' into fix/108123_add_utility_assert_listeners_comp…
nicktindall Jun 9, 2024
83f3145
fix whitespace
nicktindall Jun 9, 2024
3507494
Test that assertAtLeastOnce delegates correctly
nicktindall Jun 9, 2024
890df5d
Simplify regex
nicktindall Jun 9, 2024
df408e4
Remove variable
nicktindall Jun 9, 2024
94ab0e9
Merge branch 'main' into fix/108123_add_utility_assert_listeners_comp…
nicktindall Jun 11, 2024
3fbd9f5
Tidy tests, add tests for LeakTracker
nicktindall Jun 11, 2024
628034f
Tidy up
nicktindall Jun 11, 2024
2bc3635
Remove unnecessary code
nicktindall Jun 11, 2024
29947e5
De-verbose-ify
nicktindall Jun 11, 2024
ad3a53c
Merge branch 'main' into fix/108123_add_utility_assert_listeners_comp…
nicktindall Jun 11, 2024
884238d
Don't use #runBefore because it changes semantics to exactly-once
nicktindall Jun 11, 2024
344477f
LeakTrackerTest improvements
nicktindall Jun 11, 2024
3372f44
Delete LeakTrackerTests (to introduce in a separate PR)
nicktindall Jun 11, 2024
cbb962e
Add message to assertLeakDetected
nicktindall Jun 11, 2024
076ed95
Update server/src/test/java/org/elasticsearch/action/ActionListenerTe…
nicktindall Jun 13, 2024
07f7127
Review feedback
nicktindall Jun 13, 2024
e45718b
Merge branch 'main' into fix/108123_add_utility_assert_listeners_comp…
nicktindall Jun 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ public void testAssertAtLeastOnceWillLogAssertionErrorWhenNotResolved() throws E
final AtomicReference<ActionListener<Object>> listenerRef = new AtomicReference<>(
ActionListener.assertAtLeastOnce(ActionListener.noop())
);
// Nullify reference so it becomes unreachable
listenerRef.set(null);
assertBusy(() -> {
// Nullify reference so it becomes unreachable
listenerRef.set(null);
System.gc();
mockLog.assertAllExpectationsMatched();
});
Expand All @@ -406,16 +406,16 @@ public void testAssertAtLeastOnceWillInvokeListenerWhenNotResolved() throws Exce
listenerCreatedAt.set(createdAt);
})
);
// Nullify reference so it becomes unreachable
listenerRef.set(null);
assertBusy(() -> {
// Nullify reference so it becomes unreachable
listenerRef.set(null);
System.gc();
assertNotNull(notCalledListener.get());
assertNotNull(listenerCreatedAt.get());
});
}
nicktindall marked this conversation as resolved.
Show resolved Hide resolved

public void testAssertAtLeastOnceWillNotLogWhenResolvedOrFailed() throws Exception {
public void testAssertAtLeastOnceWillNotLogWhenResolvedOrFailed() {
final ReachabilityChecker reachabilityChecker = new ReachabilityChecker();
final AtomicBoolean notCalledListenerCalled = new AtomicBoolean();
AtomicReference<ActionListener<Object>> listenerRef = new AtomicReference<>(
Expand All @@ -434,13 +434,11 @@ public void testAssertAtLeastOnceWillNotLogWhenResolvedOrFailed() throws Excepti
listenerRef.get().onFailure(new RuntimeException("Failed"));
}
});
assertBusy(() -> {
// Nullify reference so it becomes unreachable
listenerRef.set(null);
System.gc();
reachabilityChecker.ensureUnreachable(); // Only proceed once we know the object isn't reachable
assertFalse(notCalledListenerCalled.get());
});
// Nullify reference so it becomes unreachable
listenerRef.set(null);
System.gc();
nicktindall marked this conversation as resolved.
Show resolved Hide resolved
reachabilityChecker.ensureUnreachable(); // Only proceed once we know the object isn't reachable
assertFalse(notCalledListenerCalled.get());
}

/**
Expand Down