Skip to content

Commit 3e8f151

Browse files
219sansimggivo
andauthored
Fix flaky tests in DocumentTest (#3617)
* Fix flaky tests in DocumentTest * toString() tested only in dedicated test * formating --------- Co-authored-by: ggivo <[email protected]>
1 parent d8a8eef commit 3e8f151

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/test/java/redis/clients/jedis/modules/search/DocumentTest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import redis.clients.jedis.search.Document;
1414

1515
import static org.junit.jupiter.api.Assertions.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
1617

1718
public class DocumentTest {
1819

@@ -38,13 +39,8 @@ public void serialize() throws IOException, ClassNotFoundException {
3839

3940
assertEquals(id, read.getId());
4041
assertEquals(score, read.getScore(), 0d);
41-
42-
// use english language to make sure the decimal separator is the same as the toString
43-
String exp = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s",
44-
id, score, "[string=c, float=12.0]");
45-
assertEquals(exp, read.toString());
4642
assertEquals("c", read.getString("string"));
47-
assertEquals(Double.valueOf(12d), read.get("float"));
43+
assertEquals(12d, read.get("float"));
4844
}
4945

5046
@Test
@@ -57,8 +53,14 @@ public void toStringTest() {
5753
Document document = new Document(id, map, score);
5854

5955
// use english language to make sure the decimal separator is the same as the toString
60-
String expected = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s",
61-
id, score, "[string=c, float=12.0]");
62-
assertEquals(expected, document.toString());
56+
String expected1 = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s", id, score,
57+
"[string=c, float=12.0]");
58+
String expected2 = String.format(Locale.ENGLISH, "id:%s, score: %.1f, properties:%s", id, score,
59+
"[float=12.0, string=c]");
60+
61+
// the order of the properties is not guaranteed, so we check both possible outcomes
62+
String actual = document.toString();
63+
assertTrue(actual.equals(expected1) || actual.equals(expected2));
6364
}
65+
6466
}

0 commit comments

Comments
 (0)