From 2f3c352000a3c7afa03f62ade01fc88dd5eb961a Mon Sep 17 00:00:00 2001 From: sandhu5 Date: Thu, 16 Nov 2023 10:43:58 -0600 Subject: [PATCH 1/3] Fix flaky tests in DocumentTest --- .../jedis/modules/search/DocumentTest.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/test/java/redis/clients/jedis/modules/search/DocumentTest.java b/src/test/java/redis/clients/jedis/modules/search/DocumentTest.java index 490837ebd4..1ba0b38744 100644 --- a/src/test/java/redis/clients/jedis/modules/search/DocumentTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/DocumentTest.java @@ -1,6 +1,7 @@ package redis.clients.jedis.modules.search; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -40,9 +41,12 @@ public void serialize() throws IOException, ClassNotFoundException { assertEquals(score, read.getScore(), 0d); // use english language to make sure the decimal separator is the same as the toString - String exp = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s", + String exp1 = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s", id, score, "[string=c, float=12.0]"); - assertEquals(exp, read.toString()); + String exp2 = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s", + id, score, "[float=12.0, string=c]"); + String actual = read.toString(); + assertTrue(actual.equals(exp1)||actual.equals(exp2)); assertEquals("c", read.getString("string")); assertEquals(Double.valueOf(12d), read.get("float")); } @@ -57,8 +61,11 @@ public void toStringTest() { Document document = new Document(id, map, score); // use english language to make sure the decimal separator is the same as the toString - String expected = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s", + String expected1 = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s", id, score, "[string=c, float=12.0]"); - assertEquals(expected, document.toString()); + String expected2 = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s", + id, score, "[float=12.0, string=c]"); + String actual = document.toString(); + assertTrue(actual.equals(expected1)||actual.equals(expected2)); } } From b08236ad1094fa7e12293efe4928244eb54a105b Mon Sep 17 00:00:00 2001 From: ggivo Date: Wed, 28 May 2025 09:39:50 +0300 Subject: [PATCH 2/3] toString() tested only in dedicated test --- .../clients/jedis/modules/search/DocumentTest.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/test/java/redis/clients/jedis/modules/search/DocumentTest.java b/src/test/java/redis/clients/jedis/modules/search/DocumentTest.java index 1ba0b38744..04472fba5e 100644 --- a/src/test/java/redis/clients/jedis/modules/search/DocumentTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/DocumentTest.java @@ -39,16 +39,8 @@ public void serialize() throws IOException, ClassNotFoundException { assertEquals(id, read.getId()); assertEquals(score, read.getScore(), 0d); - - // use english language to make sure the decimal separator is the same as the toString - String exp1 = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s", - id, score, "[string=c, float=12.0]"); - String exp2 = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s", - id, score, "[float=12.0, string=c]"); - String actual = read.toString(); - assertTrue(actual.equals(exp1)||actual.equals(exp2)); assertEquals("c", read.getString("string")); - assertEquals(Double.valueOf(12d), read.get("float")); + assertEquals(12d, read.get("float")); } @Test @@ -65,6 +57,8 @@ public void toStringTest() { id, score, "[string=c, float=12.0]"); String expected2 = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s", id, score, "[float=12.0, string=c]"); + + // the order of the properties is not guaranteed, so we check both possible outcomes String actual = document.toString(); assertTrue(actual.equals(expected1)||actual.equals(expected2)); } From 41dfb29bfc455860b9f371c979439715183b4307 Mon Sep 17 00:00:00 2001 From: ggivo Date: Wed, 28 May 2025 09:45:30 +0300 Subject: [PATCH 3/3] formating --- .../clients/jedis/modules/search/DocumentTest.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/test/java/redis/clients/jedis/modules/search/DocumentTest.java b/src/test/java/redis/clients/jedis/modules/search/DocumentTest.java index 13c5007663..5271dc1551 100644 --- a/src/test/java/redis/clients/jedis/modules/search/DocumentTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/DocumentTest.java @@ -13,6 +13,7 @@ import redis.clients.jedis.search.Document; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class DocumentTest { @@ -52,13 +53,14 @@ public void toStringTest() { Document document = new Document(id, map, score); // use english language to make sure the decimal separator is the same as the toString - String expected1 = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s", - id, score, "[string=c, float=12.0]"); - String expected2 = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s", - id, score, "[float=12.0, string=c]"); + String expected1 = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s", id, score, + "[string=c, float=12.0]"); + String expected2 = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s", id, score, + "[float=12.0, string=c]"); // the order of the properties is not guaranteed, so we check both possible outcomes String actual = document.toString(); - assertTrue(actual.equals(expected1)||actual.equals(expected2)); + assertTrue(actual.equals(expected1) || actual.equals(expected2)); } + }