From 1c5f5d6493c735c89234c698fd4219bc92de0169 Mon Sep 17 00:00:00 2001 From: Darius Maitia Date: Thu, 3 Apr 2025 11:19:40 +0200 Subject: [PATCH] Fix flaky query tests --- zenoh-java/src/jvmTest/java/io/zenoh/GetTest.java | 3 ++- zenoh-java/src/jvmTest/java/io/zenoh/QuerierTest.java | 3 ++- zenoh-java/src/jvmTest/java/io/zenoh/QueryableTest.java | 8 ++++---- .../src/jvmTest/java/io/zenoh/UserAttachmentTest.java | 6 ++++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/zenoh-java/src/jvmTest/java/io/zenoh/GetTest.java b/zenoh-java/src/jvmTest/java/io/zenoh/GetTest.java index b929bb92..64a0a5e9 100644 --- a/zenoh-java/src/jvmTest/java/io/zenoh/GetTest.java +++ b/zenoh-java/src/jvmTest/java/io/zenoh/GetTest.java @@ -55,13 +55,14 @@ public void tearDown() throws ZError { } @Test - public void get_runsWithCallbackTest() throws ZError { + public void get_runsWithCallbackTest() throws ZError, InterruptedException { Reply[] reply = new Reply[1]; var getOptions = new GetOptions(); getOptions.setTimeout(Duration.ofMillis(1000)); session.get(selector, reply1 -> reply[0] = reply1, getOptions); + Thread.sleep(1000); assertNotNull(reply[0]); Sample sample = ((Reply.Success) reply[0]).getSample(); assertEquals(payload, sample.getPayload()); diff --git a/zenoh-java/src/jvmTest/java/io/zenoh/QuerierTest.java b/zenoh-java/src/jvmTest/java/io/zenoh/QuerierTest.java index b8d33948..7823a73f 100644 --- a/zenoh-java/src/jvmTest/java/io/zenoh/QuerierTest.java +++ b/zenoh-java/src/jvmTest/java/io/zenoh/QuerierTest.java @@ -51,7 +51,7 @@ public class QuerierTest { * Test validating both Queryable and get operations. */ @Test - public void querier_runsWithCallbackTest() throws ZError { + public void querier_runsWithCallbackTest() throws ZError, InterruptedException { var sample = new Sample( testKeyExpr, testPayload, @@ -91,6 +91,7 @@ public void querier_runsWithCallbackTest() throws ZError { options ); + Thread.sleep(1000); assertNotNull(receivedReply[0]); assertEquals(sample, ((Reply.Success) receivedReply[0]).getSample()); diff --git a/zenoh-java/src/jvmTest/java/io/zenoh/QueryableTest.java b/zenoh-java/src/jvmTest/java/io/zenoh/QueryableTest.java index da8d72f2..8a2da00e 100644 --- a/zenoh-java/src/jvmTest/java/io/zenoh/QueryableTest.java +++ b/zenoh-java/src/jvmTest/java/io/zenoh/QueryableTest.java @@ -44,7 +44,7 @@ public void tearDown() throws ZError { } @Test - public void queryableRunsWithCallback() throws ZError { + public void queryableRunsWithCallback() throws ZError, InterruptedException { var timestamp = new TimeStamp(Date.from(Instant.now())); var sample = new Sample( @@ -70,7 +70,7 @@ public void queryableRunsWithCallback() throws ZError { Reply[] reply = new Reply[1]; session.get(testKeyExpr.into(), reply1 -> reply[0] = reply1); - + Thread.sleep(1000); assertNotNull(reply[0]); Sample receivedSample = ((Reply.Success) reply[0]).getSample(); assertEquals(sample, receivedSample); @@ -130,7 +130,7 @@ public void queryTest() throws ZError, InterruptedException { } @Test - public void queryReplySuccessTest() throws ZError { + public void queryReplySuccessTest() throws ZError, InterruptedException { var message = ZBytes.from("Test message"); var timestamp = TimeStamp.getCurrentTime(); @@ -149,7 +149,7 @@ public void queryReplySuccessTest() throws ZError { Reply[] receivedReply = new Reply[1]; session.get(testKeyExpr, reply -> receivedReply[0] = reply); - + Thread.sleep(1000); queryable.close(); assertNotNull(receivedReply[0]); diff --git a/zenoh-java/src/jvmTest/java/io/zenoh/UserAttachmentTest.java b/zenoh-java/src/jvmTest/java/io/zenoh/UserAttachmentTest.java index 1f0a4d2f..dfa1ad0f 100644 --- a/zenoh-java/src/jvmTest/java/io/zenoh/UserAttachmentTest.java +++ b/zenoh-java/src/jvmTest/java/io/zenoh/UserAttachmentTest.java @@ -171,7 +171,7 @@ public void queryWithAttachmentTest() throws ZError { } @Test - public void queryReplyWithAttachmentTest() throws ZError { + public void queryReplyWithAttachmentTest() throws ZError, InterruptedException { Reply[] reply = new Reply[1]; var queryable = session.declareQueryable(keyExpr, query -> { try { @@ -191,6 +191,7 @@ public void queryReplyWithAttachmentTest() throws ZError { queryable.close(); + Thread.sleep(1000); Reply receivedReply = reply[0]; assertNotNull(receivedReply); ZBytes receivedAttachment = ((Reply.Success) receivedReply).getSample().getAttachment(); @@ -198,7 +199,7 @@ public void queryReplyWithAttachmentTest() throws ZError { } @Test - public void queryReplyWithoutAttachmentTest() throws ZError { + public void queryReplyWithoutAttachmentTest() throws ZError, InterruptedException { Reply[] reply = new Reply[1]; var queryable = session.declareQueryable(keyExpr, query -> { try { @@ -211,6 +212,7 @@ public void queryReplyWithoutAttachmentTest() throws ZError { queryable.close(); + Thread.sleep(1000); Reply receivedReply = reply[0]; assertNotNull(receivedReply); ZBytes receivedAttachment = ((Reply.Success) receivedReply).getSample().getAttachment();