Skip to content

Commit 74bad18

Browse files
committed
Weaken random date formatter test assertion
`ESTestCase#testRandomDateFormatterPattern` previously asserted that round tripping `millis -> text -> millis` wouldn't lose any precision. But some date formats don't include the time of day so, of course, this could lose precision. This replaces that with an assertion that `text -> millis -> text` doesn't lose precision. Which should be true for any sane date format. Really, we're just trying to make sure that the random date formats that we return are *fairly* sane.
1 parent 1fe42c9 commit 74bad18

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

test/framework/src/test/java/org/elasticsearch/test/test/ESTestCaseTests.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@ public void testBasePortIDE() {
204204

205205
public void testRandomDateFormatterPattern() {
206206
DateFormatter formatter = DateFormatter.forPattern(randomDateFormatterPattern());
207-
assertThat(formatter.parseMillis(formatter.formatMillis(0)), equalTo(0L));
207+
/*
208+
* Make sure it doesn't crash trying to format some dates and
209+
* that round tripping through millis doesn't lose any information.
210+
* Interestingly, round tripping through a string *can* lose
211+
* information because not all date formats spit out milliseconds.
212+
* Hell, not all of them spit out the time of day at all!
213+
* But going from text back to millis back to text should
214+
* be fine!
215+
*/
216+
String formatted = formatter.formatMillis(randomLongBetween(0, 2_000_000_000_000L));
217+
String formattedAgain = formatter.formatMillis(formatter.parseMillis(formatted));
218+
assertThat(formattedAgain, equalTo(formatted));
208219
}
209220
}

0 commit comments

Comments
 (0)