-
Notifications
You must be signed in to change notification settings - Fork 201
loadbalancer: make address assertion in LoadBalancerTest order-independent #3357
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
Changes from 4 commits
1192610
22e5b20
f5f1972
a4d4717
f3373a0
75592a6
d615f15
ab728ae
f270486
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ | |
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
@@ -59,6 +60,7 @@ | |
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import java.util.function.Predicate; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static io.servicetalk.client.api.ServiceDiscovererEvent.Status.AVAILABLE; | ||
| import static io.servicetalk.client.api.ServiceDiscovererEvent.Status.EXPIRED; | ||
|
|
@@ -88,9 +90,11 @@ | |
| import static org.hamcrest.Matchers.anyOf; | ||
| import static org.hamcrest.Matchers.both; | ||
| import static org.hamcrest.Matchers.contains; | ||
| import static org.hamcrest.Matchers.containsInAnyOrder; | ||
| import static org.hamcrest.Matchers.empty; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.greaterThan; | ||
| import static org.hamcrest.Matchers.hasProperty; | ||
| import static org.hamcrest.Matchers.hasSize; | ||
| import static org.hamcrest.Matchers.instanceOf; | ||
| import static org.hamcrest.Matchers.is; | ||
|
|
@@ -701,7 +705,11 @@ void resubscribeToEventsWhenAllHostsAreUnhealthy() throws Exception { | |
|
|
||
| // Events for the new Subscriber change the state | ||
| sendServiceDiscoveryEvents(upEvent("address-2"), upEvent("address-3"), upEvent("address-4")); | ||
| assertAddresses(lb.usedAddresses(), "address-2", "address-3", "address-4"); | ||
| assertThat(lb.usedAddresses(), containsInAnyOrder( | ||
| hasProperty("key", is("address-2")), | ||
| hasProperty("key", is("address-3")), | ||
| hasProperty("key", is("address-4")) | ||
| )); | ||
|
|
||
| // Verify the LB is recovered | ||
| Map<String, Matcher<? super String>> expected = new HashMap<>(); | ||
|
|
@@ -712,11 +720,14 @@ void resubscribeToEventsWhenAllHostsAreUnhealthy() throws Exception { | |
| assertThat(selected1, is(anyOf(expected.values()))); | ||
|
|
||
| if (isRoundRobin()) { | ||
| // These asserts are flaky for p2c because we don't have deterministic selection. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is still valuable. |
||
| expected.remove(selected1); | ||
| assertThat(lb.selectConnection(any(), null).toFuture().get().address(), is(anyOf(expected.values()))); | ||
| assertConnectionCount(lb.usedAddresses(), connectionsCount("address-2", 0), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a similar problem with |
||
| connectionsCount("address-3", 1), connectionsCount("address-4", 1)); | ||
| Map<String, Integer> connectionCounts = lb.usedAddresses().stream() | ||
| .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().size())); | ||
|
|
||
| assertEquals(0, connectionCounts.getOrDefault("address-2", -1).intValue(), "address-2 count mismatch"); | ||
| assertEquals(1, connectionCounts.getOrDefault("address-3", -1).intValue(), "address-3 count mismatch"); | ||
| assertEquals(1, connectionCounts.getOrDefault("address-4", -1).intValue(), "address-4 count mismatch"); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory this will affect all uses of
assertAddresses: can we fixassertAddressesdirectly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will investigate a way to fix assertAddress and assertConnectionCount directly!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hello @bryce-anderson, i have made changes to edit assertAddresses and assertConnectionCount! I have changed assertConnectionCount to use a
containsInAnyOrderinstead of acontainsduring the assertion, and used a list to iterate through the addresses for assertAddresses. the tests should now pass with both./gradlew :servicetalk-loadbalancer:test --tests <qualified_test_path>and./gradlew :servicetalk-loadbalancer:nondexTest --tests <qualified_test_path>I removed ordering assumptions and avoided Hamcrest reflection matchers, comparing actual extracted keys instead. Because p2c didn't have deterministic selection, I used containsInAnyOrder to match this behavior