Skip to content

Commit c20ea9a

Browse files
edsavageDavid Roberts
authored andcommitted
[ML][TEST] Fix failing test testPersistJobOnGracefulShutdown_givenTimeAdvancedAfterNoNewData (#40363)
Ensure that there is at least a 1s delay between the time that state is persisted by each of the two jobs in the test. Model snapshot IDs use the current time in epoch seconds to distinguish themselves, hence snapshots will be overwritten by another if it occurs in the same 1s window. Closes #40347
1 parent 6f03a6c commit c20ea9a

File tree

1 file changed

+10
-3
lines changed
  • x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration

1 file changed

+10
-3
lines changed

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/PersistJobIT.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public void testPersistJob() throws Exception {
5151
}
5252

5353
// check that state is persisted after time has been advanced even if no new data is seen in the interim
54-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/40347")
5554
public void testPersistJobOnGracefulShutdown_givenTimeAdvancedAfterNoNewData() throws Exception {
5655
String jobId = "time-advanced-after-no-new-data-test";
5756

@@ -60,6 +59,7 @@ public void testPersistJobOnGracefulShutdown_givenTimeAdvancedAfterNoNewData() t
6059
FlushJobAction.Response flushResponse = flushJob(jobId, true);
6160

6261
closeJob(jobId);
62+
long job1CloseTime = System.currentTimeMillis() / 1000;
6363

6464
// Check that state has been persisted
6565
SearchResponse stateDocsResponse1 = client().prepareSearch(AnomalyDetectorsIndex.jobStateIndexPattern())
@@ -71,7 +71,7 @@ public void testPersistJobOnGracefulShutdown_givenTimeAdvancedAfterNoNewData() t
7171
int numQuantileRecords = 0;
7272
int numStateRecords = 0;
7373
for (SearchHit hit : stateDocsResponse1.getHits().getHits()) {
74-
logger.info(hit.getId());
74+
logger.info("1: " + hit.getId());
7575
if (hit.getId().contains("quantiles")) {
7676
++numQuantileRecords;
7777
} else if (hit.getId().contains("model_state")) {
@@ -82,6 +82,13 @@ public void testPersistJobOnGracefulShutdown_givenTimeAdvancedAfterNoNewData() t
8282
assertThat(numQuantileRecords, equalTo(1));
8383
assertThat(numStateRecords, equalTo(1));
8484

85+
// To generate unique snapshot IDs ensure that there is at least a 1s delay between the
86+
// time each job was closed
87+
assertBusy(() -> {
88+
long timeNow = System.currentTimeMillis() / 1000;
89+
assertFalse(job1CloseTime >= timeNow);
90+
});
91+
8592
// re-open the job
8693
openJob(jobId);
8794

@@ -104,7 +111,7 @@ public void testPersistJobOnGracefulShutdown_givenTimeAdvancedAfterNoNewData() t
104111
numQuantileRecords = 0;
105112
numStateRecords = 0;
106113
for (SearchHit hit : stateDocsResponse2.getHits().getHits()) {
107-
logger.info(hit.getId());
114+
logger.info("2: " + hit.getId());
108115
if (hit.getId().contains("quantiles")) {
109116
++numQuantileRecords;
110117
} else if (hit.getId().contains("model_state")) {

0 commit comments

Comments
 (0)