Skip to content

Commit 6c28218

Browse files
authored
Merge pull request #1667 from yue9944882/flake/relax-from-configmap-timeout
Flake: Relaxing FromConfigMap tests timeout to 2s
2 parents 2635de4 + 245144f commit 6c28218

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

spring/src/test/java/io/kubernetes/client/spring/extended/manifests/KubernetesFromConfigMapTest.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
*/
1313
package io.kubernetes.client.spring.extended.manifests;
1414

15-
import static junit.framework.Assert.assertNull;
1615
import static junit.framework.TestCase.assertEquals;
1716
import static junit.framework.TestCase.assertNotNull;
17+
import static org.awaitility.Awaitility.await;
1818

1919
import io.kubernetes.client.openapi.models.V1ConfigMap;
2020
import io.kubernetes.client.spring.extended.manifests.annotation.FromConfigMap;
@@ -23,7 +23,6 @@
2323
import java.time.Duration;
2424
import java.util.Map;
2525
import java.util.concurrent.atomic.AtomicReference;
26-
import org.awaitility.Awaitility;
2726
import org.junit.Rule;
2827
import org.junit.Test;
2928
import org.junit.rules.TestRule;
@@ -98,8 +97,9 @@ public void testValueUpdate() throws InterruptedException {
9897
assertEquals("bar1", myBean.dynamicData.get("foo"));
9998
mockAtomicConfigMapGetter.configMapAtomicReference.set(
10099
new V1ConfigMap().putDataItem("foo", "bar2"));
101-
Thread.sleep(manifestsProperties.getRefreshInterval().toMillis());
102-
assertEquals("bar2", myBean.dynamicData.get("foo"));
100+
await()
101+
.timeout(manifestsProperties.getRefreshInterval().multipliedBy(2))
102+
.until(() -> "bar2".equals(myBean.dynamicData.get("foo")));
103103
}
104104

105105
@Test
@@ -109,14 +109,13 @@ public void testKeyUpdate() throws InterruptedException {
109109
assertEquals("bar1", myBean.dynamicData.get("foo"));
110110
mockAtomicConfigMapGetter.configMapAtomicReference.set(
111111
new V1ConfigMap().putDataItem("foo1", "bar"));
112-
Thread.sleep(manifestsProperties.getRefreshInterval().toMillis());
113-
assertNull(myBean.dynamicData.get("foo")); // old key should be removed
114-
assertEquals("bar", myBean.dynamicData.get("foo1")); // new key should be added
115-
}
116-
117-
private void reset() {
118-
mockAtomicConfigMapGetter.configMapAtomicReference.set(
119-
new V1ConfigMap().putDataItem("foo", "bar1"));
112+
await()
113+
.timeout(manifestsProperties.getRefreshInterval().multipliedBy(2))
114+
.until(
115+
() -> {
116+
return myBean.dynamicData.get("foo") == null
117+
&& "bar".equals(myBean.dynamicData.get("foo1"));
118+
});
120119
}
121120

122121
static class MockConfigMapGetter implements ConfigMapGetter {
@@ -144,7 +143,7 @@ public Statement apply(Statement statement, Description description) {
144143
public void evaluate() throws Throwable {
145144
mockAtomicConfigMapGetter.configMapAtomicReference.set(
146145
new V1ConfigMap().putDataItem("foo", "bar1"));
147-
Awaitility.await().until(() -> "bar1".equals(myBean.dynamicData.get("foo")));
146+
await().until(() -> "bar1".equals(myBean.dynamicData.get("foo")));
148147
statement.evaluate();
149148
}
150149
};

0 commit comments

Comments
 (0)