Skip to content
Open
Changes from 5 commits
Commits
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 @@ -553,53 +553,57 @@ void cacheReflectsAttributeChanges() throws InterruptedException {
final AtomicLong updateInvokedCounter = new AtomicLong();
final Consumer<List<Endpoint>> endpointsListener = endpoints -> updateInvokedCounter.incrementAndGet();

try (HealthCheckedEndpointGroup endpointGroup =
new HealthCheckedEndpointGroup(delegate, true,
10000, 10000,
SessionProtocol.HTTP, 80,
DEFAULT_HEALTH_CHECK_RETRY_BACKOFF,
ClientOptions.of(), checkFactory,
HealthCheckStrategy.all(),
DEFAULT_ENDPOINT_PREDICATE)) {
endpointGroup.addListener(endpointsListener, true);
await().untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(1));
// the counter should stay 1 after 1 second has passed
await().pollDelay(1, TimeUnit.SECONDS)
.untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(1));
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.DEGRADED_ATTR))
.isFalse();
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.HEALTHY_ATTR))
.isTrue();

headers.set(ResponseHeaders.of(HttpStatus.OK, "x-envoy-degraded", ""));
// the counter should be incremented to three now
await().untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(2));
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.DEGRADED_ATTR))
.isTrue();
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.HEALTHY_ATTR))
.isTrue();

// the counter should be incremented to two now
healthy.set(0);
await().untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(3));
assertThat(endpointGroup.endpoints()).isEmpty();

// healthy again
healthy.set(1);
await().untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(4));
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.HEALTHY_ATTR))
.isTrue();
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.DEGRADED_ATTR))
.isTrue();

// turn off degraded again
headers.set(null);
await().untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(5));
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.HEALTHY_ATTR))
.isTrue();
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.DEGRADED_ATTR))
.isFalse();
}
final HealthCheckedEndpointGroup endpointGroup = new HealthCheckedEndpointGroup(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question) Shouldn't the HealthCheckedEndpointGroup still be closed to close the ScheduledFuture at L539?

delegate, true,
10000, 10000,
SessionProtocol.HTTP, 80,
DEFAULT_HEALTH_CHECK_RETRY_BACKOFF,
ClientOptions.of(), checkFactory,
HealthCheckStrategy.all(),
DEFAULT_ENDPOINT_PREDICATE
);

endpointGroup.whenReady().join();
endpointGroup.addListener(endpointsListener, false);
endpointsListener.accept(endpointGroup.endpoints());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we do this?

Suggested change
endpointGroup.addListener(endpointsListener, false);
endpointsListener.accept(endpointGroup.endpoints());
endpointGroup.addListener(endpointsListener, true);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works ! I think Fix duplicate endpoint handling in HealthCheckedEndpointGroup
this change helps the new group include endpoints from the previous group temporarily, which avoids any brief disappearance during the transition.


await().untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(1));
// the counter should stay 1 after 1 second has passed
await().pollDelay(1, TimeUnit.SECONDS)
.untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(1));
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.DEGRADED_ATTR))
.isFalse();
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.HEALTHY_ATTR))
.isTrue();

headers.set(ResponseHeaders.of(HttpStatus.OK, "x-envoy-degraded", ""));
// the counter should be incremented to three now
await().untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(2));
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.DEGRADED_ATTR))
.isTrue();
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.HEALTHY_ATTR))
.isTrue();

// the counter should be incremented to two now
healthy.set(0);
await().untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(3));
assertThat(endpointGroup.endpoints()).isEmpty();

// healthy again
healthy.set(1);
await().untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(4));
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.HEALTHY_ATTR))
.isTrue();
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.DEGRADED_ATTR))
.isTrue();

// turn off degraded again
headers.set(null);
await().untilAsserted(() -> assertThat(updateInvokedCounter).hasValue(5));
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.HEALTHY_ATTR))
.isTrue();
assertThat(endpointGroup.endpoints().get(0).attrs().attr(EndpointAttributeKeys.DEGRADED_ATTR))
.isFalse();
}

@Test
Expand Down
Loading