You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by rz...@apache.org on 2026/08/20 10:15:55 UTC
(openjpa) 01/01: Fix flaky KubernetesTCPRemoteCommitProviderTest
This is an automated email from the ASF dual-hosted git repository.
rzo1 pushed a commit to branch OPENJPA-kubernetes-flaky-test
in repository https://gitbox.apache.org/repos/asf/openjpa.git
commit 04a138dcbff9baf103ea9c6a19ee9457bab35db6
Author: Richard Zowalla <rz...@apache.org>
AuthorDate: Thu Aug 20 12:12:23 2026 +0200
Fix flaky KubernetesTCPRemoteCommitProviderTest
fetchDynamicAddresses() closes the client returned by kubernetesClient()
(try-with-resources), so handing out the shared client of the mock server
made every refresh after the first one fail with an already-closed client.
DynamicTCPRemoteCommitProvider.endConfiguration() runs the updater once
synchronously and then schedules it with an initial delay of 0, so a second
run always races the assertions: if it won, all addresses were removed again
and the test saw 0 instead of 2.
Hand out a fresh client per invocation, as the production implementation
does, and assert that the addresses survive the scheduled refreshes.
---
.../KubernetesTCPRemoteCommitProviderTest.java | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/openjpa-kubernetes/src/test/java/org/apache/openjpa/event/kubernetes/KubernetesTCPRemoteCommitProviderTest.java b/openjpa-kubernetes/src/test/java/org/apache/openjpa/event/kubernetes/KubernetesTCPRemoteCommitProviderTest.java
index ff8a9ee2d..a15daad57 100644
--- a/openjpa-kubernetes/src/test/java/org/apache/openjpa/event/kubernetes/KubernetesTCPRemoteCommitProviderTest.java
+++ b/openjpa-kubernetes/src/test/java/org/apache/openjpa/event/kubernetes/KubernetesTCPRemoteCommitProviderTest.java
@@ -49,6 +49,8 @@ public class KubernetesTCPRemoteCommitProviderTest {
private static final String LABEL = "testKey";
+ private static final int REFRESH_MILLIS = 100;
+
private static List<String> getAddresses(final KubernetesTCPRemoteCommitProvider rcp)
throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
@@ -138,14 +140,17 @@ public class KubernetesTCPRemoteCommitProviderTest {
@Override
protected KubernetesClient kubernetesClient() throws KubernetesClientException {
- return server.getClient();
+ // a fresh client per invocation, as done by the base implementation:
+ // fetchDynamicAddresses() closes the client it is given, so handing out the
+ // shared client of the mock server would make every subsequent refresh fail
+ // and hence drop all addresses again
+ return server.getKubernetesMockServer().createClient();
}
};
rcp.setNamespace(NAMESPACE);
rcp.setLabel(LABEL);
- // mock will drop all IPs if test will run too long.
- // 5 sec should be enough
- rcp.setCacheDurationMillis(5000);
+ // refresh often, so that the assertions below cover the scheduled refreshes as well
+ rcp.setCacheDurationMillis(REFRESH_MILLIS);
// mock OpenJPA configuration
Configuration conf = context.mock(Configuration.class);
@@ -162,6 +167,15 @@ public class KubernetesTCPRemoteCommitProviderTest {
rcp.endConfiguration();
// expect to find remote addresses of matching pods
+ assertAddresses(rcp);
+
+ // the addresses are periodically refreshed in the background: expect them to be
+ // still there after some refreshes have taken place
+ Thread.sleep(5 * REFRESH_MILLIS);
+ assertAddresses(rcp);
+ }
+
+ private void assertAddresses(final KubernetesTCPRemoteCommitProvider rcp) throws Exception {
List<String> addresses = getAddresses(rcp);
assertEquals(2, addresses.size());
assertTrue(addresses.contains(pod1.getStatus().getPodIP()));