KAFKA-14780: Fix flaky test 'testSecondaryRefreshAfterElapsedDelay' (#14078)
"The test RefreshingHttpsJwksTest#testSecondaryRefreshAfterElapsedDelay relies on the actual system clock, which makes it frequently fail. The fix adds a second constructor that allows for passing a ScheduledExecutorService to manually execute the scheduled tasks before refreshing. The fixed task is much more robust and stable.
Co-authored-by: Fei Xie <feixie@MacBook-Pro.attlocal.net>
Reviewers: Divij Vaidya <diviv@amazon.com>, Luke Chen <showuon@gmail.com>
@ -75,7 +76,7 @@ public final class RefreshingHttpsJwks implements Initable, Closeable {
@@ -75,7 +76,7 @@ public final class RefreshingHttpsJwks implements Initable, Closeable {
@ -121,23 +122,17 @@ public final class RefreshingHttpsJwks implements Initable, Closeable {
@@ -121,23 +122,17 @@ public final class RefreshingHttpsJwks implements Initable, Closeable {
thrownewIllegalArgumentException("JWKS validation key refresh configuration value retryWaitMs value must be positive");
@ -146,7 +141,7 @@ public final class RefreshingHttpsJwks implements Initable, Closeable {
@@ -146,7 +141,7 @@ public final class RefreshingHttpsJwks implements Initable, Closeable {
@ -155,6 +150,27 @@ public final class RefreshingHttpsJwks implements Initable, Closeable {
@@ -155,6 +150,27 @@ public final class RefreshingHttpsJwks implements Initable, Closeable {
@ -180,9 +196,9 @@ public final class RefreshingHttpsJwks implements Initable, Closeable {
@@ -180,9 +196,9 @@ public final class RefreshingHttpsJwks implements Initable, Closeable {
//
// Note: we refer to this as a _scheduled_ refresh.
log.info("JWKS validation key refresh thread started with a refresh interval of {} ms",refreshMs);
}finally{
@ -203,7 +219,7 @@ public final class RefreshingHttpsJwks implements Initable, Closeable {
@@ -203,7 +219,7 @@ public final class RefreshingHttpsJwks implements Initable, Closeable {
log.warn("JWKS validation key refresh thread termination did not end after {} {}",
SHUTDOWN_TIMEOUT,SHUTDOWN_TIME_UNIT);
SHUTDOWN_TIMEOUT,SHUTDOWN_TIME_UNIT);
}
}catch(InterruptedExceptione){
log.warn("JWKS validation key refresh thread error during close",e);
@ -217,13 +233,12 @@ public final class RefreshingHttpsJwks implements Initable, Closeable {
@@ -217,13 +233,12 @@ public final class RefreshingHttpsJwks implements Initable, Closeable {
@ -122,14 +132,36 @@ public class RefreshingHttpsJwksTest extends OAuthBearerTest {
@@ -122,14 +132,36 @@ public class RefreshingHttpsJwksTest extends OAuthBearerTest {
@ -153,6 +185,10 @@ public class RefreshingHttpsJwksTest extends OAuthBearerTest {
@@ -153,6 +185,10 @@ public class RefreshingHttpsJwksTest extends OAuthBearerTest {
@ -195,4 +231,82 @@ public class RefreshingHttpsJwksTest extends OAuthBearerTest {
@@ -195,4 +231,82 @@ public class RefreshingHttpsJwksTest extends OAuthBearerTest {