Skip to content

[CI] Tests of _cat output containing dates can fail as ZonedDateTime.toString() does not have deterministic format #32466

@droberts195

Description

@droberts195

cat.indices/10_basic/Test cat indices output failed with the following error:

FAILURE 0.12s | MixedClusterClientYamlTestSuiteIT.test {p0=cat.indices/10_basic/Test cat indices output} <<< FAILURES!
   > Throwable #1: java.lang.AssertionError: Failure at [cat.indices/10_basic:40]: field [$body] was expected to match the provided regex but didn't
   > Expected: ^(
   >    index1                                                    \s+
   >    (\d+)                                                     \s+
   >    (\d\d\d\d\-\d\d\-\d\dT\d\d:\d\d:\d\d.\d\d\dZ) \s+
   >    (\d+)                                                     \s+
   >    (\d\d\d\d\-\d\d\-\d\dT\d\d:\d\d:\d\d.\d\d\dZ) \s*
   >  )
   >  $
   >      but: was "index1 1532913914000 2018-07-30T01:25:14Z 1532913914000 2018-07-30T01:25:14Z\n"
   > 	at __randomizedtesting.SeedInfo.seed([5CE2FDA0291D51B9:D4B6C27A87E13C41]:0)
   > 	at org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase.executeSection(ESClientYamlSuiteTestCase.java:394)
   > 	at org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase.test(ESClientYamlSuiteTestCase.java:371)
   > 	at java.lang.Thread.run(Thread.java:748)
   > Caused by: java.lang.AssertionError: field [$body] was expected to match the provided regex but didn't
   > Expected: ^(
   >    index1                                                    \s+
   >    (\d+)                                                     \s+
   >    (\d\d\d\d\-\d\d\-\d\dT\d\d:\d\d:\d\d.\d\d\dZ) \s+
   >    (\d+)                                                     \s+
   >    (\d\d\d\d\-\d\d\-\d\dT\d\d:\d\d:\d\d.\d\d\dZ) \s*
   >  )
   >  $
   >      but: was "index1 1532913914000 2018-07-30T01:25:14Z 1532913914000 2018-07-30T01:25:14Z\n"
   > 	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
   > 	at org.elasticsearch.test.rest.yaml.section.MatchAssertion.doAssert(MatchAssertion.java:67)
   > 	at org.elasticsearch.test.rest.yaml.section.Assertion.execute(Assertion.java:76)
   > 	at org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase.executeSection(ESClientYamlSuiteTestCase.java:387)
   > 	... 37 more

The full log is https://elasticsearch-ci.elastic.co/job/elastic+elasticsearch+6.4+bwc-tests/6/console

Then problem is that the regex expects milliseconds but the output only contains seconds.

This does not reproduce easily. However, by making the following edit the problem will reproduce 50% of the time (presumably because it's a mixed cluster and the code edit only applies to one version):

--- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java
+++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java
@@ -380,7 +380,7 @@ public class RestIndicesAction extends AbstractCatAction {
             table.addCell(primaryStats.getDocs() == null ? null : primaryStats.getDocs().getDeleted());
 
             table.addCell(indexMetaData.getCreationDate());
-            table.addCell(ZonedDateTime.ofInstant(Instant.ofEpochMilli(indexMetaData.getCreationDate()), ZoneOffset.UTC));
+            table.addCell(ZonedDateTime.ofInstant(Instant.ofEpochSecond(indexMetaData.getCreationDate() / 1000L), ZoneOffset.UTC));
 
             table.addCell(totalStats.getStore() == null ? null : totalStats.getStore().size());
             table.addCell(primaryStats.getStore() == null ? null : primaryStats.getStore().size());

So the problem is that ZonedDateTime.toString() does not output milliseconds if the time it's storing is an exact number of seconds.

I suspect this problem is new to 6.4 due to the Joda to Java time migration.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions