Skip to content

Fix flaky query tests #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion zenoh-java/src/jvmTest/java/io/zenoh/GetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion zenoh-java/src/jvmTest/java/io/zenoh/QuerierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -91,6 +91,7 @@ public void querier_runsWithCallbackTest() throws ZError {
options
);

Thread.sleep(1000);
assertNotNull(receivedReply[0]);
assertEquals(sample, ((Reply.Success) receivedReply[0]).getSample());

Expand Down
8 changes: 4 additions & 4 deletions zenoh-java/src/jvmTest/java/io/zenoh/QueryableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down Expand Up @@ -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();

Expand All @@ -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]);
Expand Down
6 changes: 4 additions & 2 deletions zenoh-java/src/jvmTest/java/io/zenoh/UserAttachmentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -191,14 +191,15 @@ public void queryReplyWithAttachmentTest() throws ZError {

queryable.close();

Thread.sleep(1000);
Reply receivedReply = reply[0];
assertNotNull(receivedReply);
ZBytes receivedAttachment = ((Reply.Success) receivedReply).getSample().getAttachment();
assertEquals(attachment, receivedAttachment);
}

@Test
public void queryReplyWithoutAttachmentTest() throws ZError {
public void queryReplyWithoutAttachmentTest() throws ZError, InterruptedException {
Reply[] reply = new Reply[1];
var queryable = session.declareQueryable(keyExpr, query -> {
try {
Expand All @@ -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();
Expand Down
Loading