Skip to content
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

Fix HistoryIntegrationTests timestamp comparsion #38505

Merged

Conversation

pgomulka
Copy link
Contributor

@pgomulka pgomulka commented Feb 6, 2019

When the millisecond part of a timestamp is 0 the toString
representation in java-time is omitting the millisecond part (joda was
not). The Search response is returning timestamps formatted with
WatcherDateTimeUtils, therefore comparisons of strings should be done
with the same formatter

relates #27330

@pgomulka pgomulka added the :Core/Infra/Core Core issues without another label label Feb 6, 2019
@pgomulka pgomulka self-assigned this Feb 6, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@pgomulka
Copy link
Contributor Author

pgomulka commented Feb 6, 2019

This was spotted in a PR Build https://elasticsearch-ci.elastic.co/job/elastic+elasticsearch+pull-request-2/7451/console

REPRODUCE WITH: ./gradlew :x-pack:plugin:watcher:unitTest -Dtests.seed=7C3F86FEA0E888ED -Dtests.class=org.elasticsearch.xpack.watcher.test.integration.HistoryIntegrationTests -Dtests.method="testThatHistoryContainsStatus" -Dtests.security.manager=true -Dtests.locale=cs -Dtests.timezone=Asia/Chungking -Dcompiler.java=11 -Druntime.java=8

However the ClockMock has to be locally modified to have constructor fixing the time with milliseconds being 0:

 public ClockMock() {
        this(Clock.systemUTC());
setTime(DateFormatters.from(DateFormatter.forPattern("date_time").parse("2019-02-05T23:32:52.000Z")));
    }

When the millisecond part of a timestamp is 0 the toString
representation in java-time is ommiting the millisecond part (joda was
not). The Search response is returning timestamps formatted with
WatcherDateTimeUtils, therefore comparisons of strings should be done
with the same formatter
@pgomulka pgomulka force-pushed the test/watcher_joda_HistoryIntegrationTests branch from c431150 to bdd9887 Compare February 6, 2019 11:15
@cbuescher cbuescher self-requested a review February 6, 2019 13:12
Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good to me. However I'm wondering if we could change the test to be reproducable just using the random seed. Its not ideal that this test currently only fails when overwriting the ClockMock constructor. Maybe there is a way to initialize the clock used in tests with a date that depends on the random seed only and then freeze it? I don't know if this is possible in this test but I think it would be a great improvement. Could be done in a follow up PR though.

@cbuescher
Copy link
Member

@pgomulka just to follow up on my last comment, the ClockMock seems to be initalized by the TimeWarpedWatcher plugin used in watcher tests.
I have a feeling the TimeWarp which contains the clock can be accessed in AbstractWatcherIntegrationTestCase#timeWarp() and from there it
should be possible to get the clock and fix it to a date depending on the random seed. Maybe this should be done just in this test method, maybe its something
that might be useful in a @before block fixing time for everything in HistoryIntegrationTests, but I don't know. Maybe a frozen clock doesn't work with some
of the other tests in this suite.

@pgomulka
Copy link
Contributor Author

pgomulka commented Feb 6, 2019

@cbuescher yes ideally it would be great to make the time depending on the seed we provide, for instance

  public ClockMock() {
        this(Clock.systemUTC());
        int millis = LuceneTestCase.random().nextInt(1000);// what bound
        setTime(Instant.ofEpochMilli(millis));
    }

but then we would need to be sure that all the usages of ZonedDateTime.now are using a this clock, otherwise the clock would be in 1970's and other parts of code in 2019

@pgomulka
Copy link
Contributor Author

pgomulka commented Feb 6, 2019

I think this would end up a much bigger change, better to tackle that in a separate PR. We are having similar discussion on this PR: #38473

@pgomulka pgomulka merged commit a5c35f9 into elastic:master Feb 6, 2019
@cbuescher
Copy link
Member

I think this would end up a much bigger change, better to tackle that in a separate PR.

Agreed, I'm also not sure if it would be feasible in the case of HistoryIntegrationTests. I'll open an issue about it to track it though.

@cbuescher
Copy link
Member

@pgomulka can you add a version label and some sort of scope (I think its the ">test-failure" or sth. similar) to this so this gets sorted right for the release changes?

@cbuescher
Copy link
Member

I opened #38520 to track the question of missing reproducability here.

jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Feb 6, 2019
* master:
  ML: update set_upgrade_mode, add logging (elastic#38372)
  bad formatted JSON object (elastic#38515) (elastic#38525)
  Fix HistoryIntegrationTests timestamp comparsion (elastic#38505)
  SQL: Fix issue with IN not resolving to underlying keyword field (elastic#38440)
  Fix the clock resolution to millis in ScheduledEventTests (elastic#38506)
pgomulka added a commit to pgomulka/elasticsearch that referenced this pull request Feb 8, 2019
When the millisecond part of a timestamp is 0 the toString
representation in java-time is omitting the millisecond part (joda was
not). The Search response is returning timestamps formatted with
WatcherDateTimeUtils, therefore comparisons of strings should be done
with the same formatter

relates elastic#27330
pgomulka added a commit to pgomulka/elasticsearch that referenced this pull request Feb 8, 2019
When the millisecond part of a timestamp is 0 the toString
representation in java-time is omitting the millisecond part (joda was
not). The Search response is returning timestamps formatted with
WatcherDateTimeUtils, therefore comparisons of strings should be done
with the same formatter

relates elastic#27330
pgomulka added a commit that referenced this pull request Feb 8, 2019
…8505)

When the millisecond part of a timestamp is 0 the toString
representation in java-time is omitting the millisecond part (joda was
not). The Search response is returning timestamps formatted with
WatcherDateTimeUtils, therefore comparisons of strings should be done
with the same formatter

relates #27330
backport#38505
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Feb 8, 2019
* 7.0:
  Mute IndexFollowingIT.testIndexFallBehind (elastic#38618)
  Mute failing WatchStatusIntegrationTests (elastic#38621)
  Mute failing  ApiKeyIntegTests (elastic#38614)
  Fix the clock resolution to millis in ScheduledEventTests (elastic#38517)
  [DOCS] Add warning about bypassing ML PUT APIs (elastic#38606)
  Fix HistoryIntegrationTests timestamp comparsion (elastic#38566) Backport(elastic#38505)
  Mute RetentionLeastIT.testRetentionLeasesSyncOnRecovery on 7x (elastic#38600)
  Fix version logic when bumping major version (elastic#38595)
pgomulka added a commit that referenced this pull request Feb 11, 2019
When the millisecond part of a timestamp is 0 the toString
representation in java-time is omitting the millisecond part (joda was
not). The Search response is returning timestamps formatted with
WatcherDateTimeUtils, therefore comparisons of strings should be done
with the same formatter

relates #27330
BackPort #38505
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Feb 11, 2019
* master: (27 commits)
  Mute AnalysisModuleTests#testStandardFilterBWC (elastic#38636)
  add geotile_grid ref to asciidoc (elastic#38632)
  Enable Dockerfile from artifacts.elastic.co (elastic#38552)
  Mute FollowerFailOverIT testFailOverOnFollower (elastic#38634)
  Account for a possible rolled over file while reading the audit log file (elastic#34909)
  Mute failure in InternalEngineTests (elastic#38622)
  Fix Issue with Concurrent Snapshot Init + Delete (elastic#38518)
  Refactor ZonedDateTime.now in millis resolution (elastic#38577)
  Mute failing WatchStatusIntegrationTests (elastic#38621)
  Mute failing  ApiKeyIntegTests (elastic#38614)
  [DOCS] Add warning about bypassing ML PUT APIs (elastic#38509)
  Add 7.1 and 8.0 version constants to master (elastic#38514)
  ML: update set_upgrade_mode, add logging (elastic#38372)
  bad formatted JSON object (elastic#38515) (elastic#38525)
  Fix HistoryIntegrationTests timestamp comparsion (elastic#38505)
  SQL: Fix issue with IN not resolving to underlying keyword field (elastic#38440)
  Fix the clock resolution to millis in ScheduledEventTests (elastic#38506)
  Enable BWC after backport recovering leases (elastic#38485)
  Collapse retention lease integration tests (elastic#38483)
  TransportVerifyShardBeforeCloseAction should force a flush (elastic#38401)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Core Core issues without another label >test-failure Triaged test failures from CI v7.0.0-beta1 v7.2.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants