From ea3c73b0d06fc484a9d4fa721704e8a08e5ceb4c Mon Sep 17 00:00:00 2001 From: Oleg Kravchuk Date: Wed, 22 Nov 2023 01:15:55 +0200 Subject: [PATCH] Changed the "delayed continuous execution test" to be more expressive about what it should test. Signed-off-by: Oleg Kravchuk --- .../rollup/runner/RollupRunnerIT.kt | 44 ++++++------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/runner/RollupRunnerIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/runner/RollupRunnerIT.kt index 3b173515c..d76f1a40f 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/runner/RollupRunnerIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/runner/RollupRunnerIT.kt @@ -663,40 +663,24 @@ class RollupRunnerIT : RollupRestTestCase() { putDateDocumentInSourceIndex(rollup) // Create rollup job - rollup = createRollup(rollup = rollup, rollupId = rollup.id) + val jobStartTime = Instant.now() + val rollupNow = rollup.copy( + jobSchedule = IntervalSchedule(jobStartTime, 1, ChronoUnit.MINUTES), + jobEnabledTime = jobStartTime + ) + rollup = createRollup(rollup = rollupNow, rollupId = rollupNow.id) - var nextExecutionTime = rollup.schedule.getNextExecutionTime(null).toEpochMilli() - val expectedExecutionTime = rollup.jobEnabledTime!!.plusMillis(delay).toEpochMilli() - val delayIsCorrect = ((expectedExecutionTime - nextExecutionTime) > -500) && ((expectedExecutionTime - nextExecutionTime) < 500) - assertTrue("Delay was not correctly applied", delayIsCorrect) + val nextExecutionTime1 = rollup.jobSchedule.getNextExecutionTime(null).toEpochMilli() + assertTrue("The first job execution time should be after [job start time] + [delay].", nextExecutionTime1 >= jobStartTime.toEpochMilli() + delay) + assertTrue("The first job execution time should not be delayed too much after [job start time] + [delay].", nextExecutionTime1 <= jobStartTime.toEpochMilli() + delay + 100) waitFor { - // Wait until half a second before the intended execution time - assertTrue(Instant.now().toEpochMilli() >= nextExecutionTime - 500) - // Still should not have run at this point - assertFalse("Target rollup index was created before the delay should allow", indexExists(rollup.targetIndex)) + assertTrue(Instant.now().toEpochMilli() >= nextExecutionTime1) } - val rollupMetadata = waitFor { - assertTrue("Target rollup index was not created", indexExists(rollup.targetIndex)) - val rollupJob = getRollup(rollupId = rollup.id) - assertNotNull("Rollup job doesn't have metadata set", rollupJob.metadataID) - val rollupMetadata = getRollupMetadata(rollupJob.metadataID!!) - assertNotNull("Rollup metadata not found", rollupMetadata) - rollupMetadata - } - nextExecutionTime = rollup.schedule.getNextExecutionTime(null).toEpochMilli() - val nextExecutionOffset = (nextExecutionTime - Instant.now().toEpochMilli()) - 60000 - val nextExecutionIsCorrect = nextExecutionOffset < 5000 && nextExecutionOffset > -5000 - assertTrue("Next execution time not updated correctly", nextExecutionIsCorrect) - val nextWindowStartTime: Instant = rollupMetadata.continuous!!.nextWindowStartTime - val nextWindowEndTime: Instant = rollupMetadata.continuous!!.nextWindowEndTime - // Assert that after the window was updated, it falls approximately around 'now' - assertTrue("Rollup window start time is incorrect", nextWindowStartTime.plusMillis(delay).minusMillis(1000) < Instant.now()) - assertTrue("Rollup window end time is incorrect", nextWindowEndTime.plusMillis(delay).plusMillis(1000) > Instant.now()) - - // window length should be 5 seconds - val expectedWindowEnd = nextWindowStartTime.plusMillis(5000) - assertEquals("Rollup window length applied incorrectly", expectedWindowEnd, nextWindowEndTime) + + val nextExecutionTime2 = rollup.schedule.getNextExecutionTime(null).toEpochMilli() + assertTrue("The second job execution time should be not earlier than a minute after the first execution.", nextExecutionTime2 - nextExecutionTime1 >= 60000) + assertTrue("The second job execution time should not be too delayed after the first execution.", nextExecutionTime2 - nextExecutionTime1 <= 60000 + 100) } fun `test non continuous delay does nothing`() {