Skip to content

Commit ea3c73b

Browse files
committed
Changed the "delayed continuous execution test" to be more expressive about what it should test.
Signed-off-by: Oleg Kravchuk <oleg.ikibo@gmail.com>
1 parent f62b77a commit ea3c73b

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

src/test/kotlin/org/opensearch/indexmanagement/rollup/runner/RollupRunnerIT.kt

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -663,40 +663,24 @@ class RollupRunnerIT : RollupRestTestCase() {
663663
putDateDocumentInSourceIndex(rollup)
664664

665665
// Create rollup job
666-
rollup = createRollup(rollup = rollup, rollupId = rollup.id)
666+
val jobStartTime = Instant.now()
667+
val rollupNow = rollup.copy(
668+
jobSchedule = IntervalSchedule(jobStartTime, 1, ChronoUnit.MINUTES),
669+
jobEnabledTime = jobStartTime
670+
)
671+
rollup = createRollup(rollup = rollupNow, rollupId = rollupNow.id)
667672

668-
var nextExecutionTime = rollup.schedule.getNextExecutionTime(null).toEpochMilli()
669-
val expectedExecutionTime = rollup.jobEnabledTime!!.plusMillis(delay).toEpochMilli()
670-
val delayIsCorrect = ((expectedExecutionTime - nextExecutionTime) > -500) && ((expectedExecutionTime - nextExecutionTime) < 500)
671-
assertTrue("Delay was not correctly applied", delayIsCorrect)
673+
val nextExecutionTime1 = rollup.jobSchedule.getNextExecutionTime(null).toEpochMilli()
674+
assertTrue("The first job execution time should be after [job start time] + [delay].", nextExecutionTime1 >= jobStartTime.toEpochMilli() + delay)
675+
assertTrue("The first job execution time should not be delayed too much after [job start time] + [delay].", nextExecutionTime1 <= jobStartTime.toEpochMilli() + delay + 100)
672676

673677
waitFor {
674-
// Wait until half a second before the intended execution time
675-
assertTrue(Instant.now().toEpochMilli() >= nextExecutionTime - 500)
676-
// Still should not have run at this point
677-
assertFalse("Target rollup index was created before the delay should allow", indexExists(rollup.targetIndex))
678+
assertTrue(Instant.now().toEpochMilli() >= nextExecutionTime1)
678679
}
679-
val rollupMetadata = waitFor {
680-
assertTrue("Target rollup index was not created", indexExists(rollup.targetIndex))
681-
val rollupJob = getRollup(rollupId = rollup.id)
682-
assertNotNull("Rollup job doesn't have metadata set", rollupJob.metadataID)
683-
val rollupMetadata = getRollupMetadata(rollupJob.metadataID!!)
684-
assertNotNull("Rollup metadata not found", rollupMetadata)
685-
rollupMetadata
686-
}
687-
nextExecutionTime = rollup.schedule.getNextExecutionTime(null).toEpochMilli()
688-
val nextExecutionOffset = (nextExecutionTime - Instant.now().toEpochMilli()) - 60000
689-
val nextExecutionIsCorrect = nextExecutionOffset < 5000 && nextExecutionOffset > -5000
690-
assertTrue("Next execution time not updated correctly", nextExecutionIsCorrect)
691-
val nextWindowStartTime: Instant = rollupMetadata.continuous!!.nextWindowStartTime
692-
val nextWindowEndTime: Instant = rollupMetadata.continuous!!.nextWindowEndTime
693-
// Assert that after the window was updated, it falls approximately around 'now'
694-
assertTrue("Rollup window start time is incorrect", nextWindowStartTime.plusMillis(delay).minusMillis(1000) < Instant.now())
695-
assertTrue("Rollup window end time is incorrect", nextWindowEndTime.plusMillis(delay).plusMillis(1000) > Instant.now())
696-
697-
// window length should be 5 seconds
698-
val expectedWindowEnd = nextWindowStartTime.plusMillis(5000)
699-
assertEquals("Rollup window length applied incorrectly", expectedWindowEnd, nextWindowEndTime)
680+
681+
val nextExecutionTime2 = rollup.schedule.getNextExecutionTime(null).toEpochMilli()
682+
assertTrue("The second job execution time should be not earlier than a minute after the first execution.", nextExecutionTime2 - nextExecutionTime1 >= 60000)
683+
assertTrue("The second job execution time should not be too delayed after the first execution.", nextExecutionTime2 - nextExecutionTime1 <= 60000 + 100)
700684
}
701685

702686
fun `test non continuous delay does nothing`() {

0 commit comments

Comments
 (0)