Skip to content

Commit 35f797a

Browse files
[8.19] Use fixed dates to test getNextRunAt (elastic#223574) (elastic#224953)
# Backport This will backport the following commits from `main` to `8.19`: - [Use fixed dates to test getNextRunAt (elastic#223574)](elastic#223574) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Ersin Erdal","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-06-23T19:41:20Z","message":"Use fixed dates to test getNextRunAt (elastic#223574)\n\nFixes: elastic#220501","sha":"59f635c9c86ce178e5fb79ba2121d86398af922c","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","backport:version","v9.1.0","v8.19.0"],"title":"Use fixed dates to test getNextRunAt","number":223574,"url":"https://github.com/elastic/kibana/pull/223574","mergeCommit":{"message":"Use fixed dates to test getNextRunAt (elastic#223574)\n\nFixes: elastic#220501","sha":"59f635c9c86ce178e5fb79ba2121d86398af922c"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/223574","number":223574,"mergeCommit":{"message":"Use fixed dates to test getNextRunAt (elastic#223574)\n\nFixes: elastic#220501","sha":"59f635c9c86ce178e5fb79ba2121d86398af922c"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Ersin Erdal <[email protected]>
1 parent 3be94f5 commit 35f797a

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

x-pack/platform/plugins/shared/task_manager/server/lib/get_next_run_at.test.ts

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import { getNextRunAt } from './get_next_run_at';
1111
import { loggerMock } from '@kbn/logging-mocks';
1212
const mockLogger = loggerMock.create();
1313

14-
// Failing: See https://github.com/elastic/kibana/issues/220501
15-
describe.skip('getNextRunAt', () => {
14+
describe('getNextRunAt', () => {
1615
afterEach(() => {
1716
jest.clearAllMocks();
1817
});
@@ -65,8 +64,8 @@ describe.skip('getNextRunAt', () => {
6564
expect(nextRunAt.getTime()).toBeGreaterThanOrEqual(testStart.getTime());
6665
});
6766

68-
test('should use the rrule with a fixed time when it is given to calculate the next runAt', () => {
69-
const now = new Date();
67+
test('should use the rrule with a fixed time when it is given to calculate the next runAt (same day)', () => {
68+
const now = new Date('2025-06-30T10:00:00.000Z');
7069
const testStart = new Date(now.getTime() - 500);
7170
const testRunAt = new Date(now.getTime() - 1000);
7271
const nextRunAt = getNextRunAt(
@@ -86,23 +85,33 @@ describe.skip('getNextRunAt', () => {
8685
0,
8786
mockLogger
8887
);
88+
const expectedNextRunAt = new Date('2025-06-30T12:15:59.500Z');
89+
expect(nextRunAt).toEqual(expectedNextRunAt);
90+
});
8991

90-
const currentDay = testStart.getUTCDay();
91-
const currentHour = testStart.getUTCHours();
92-
const currentSecond = testStart.getUTCSeconds();
93-
const currentMilliseconds = testStart.getUTCMilliseconds();
94-
95-
if (currentHour < 12) {
96-
expect(nextRunAt.getUTCDay()).toBe(currentDay);
97-
} else {
98-
const tomorrow = new Date();
99-
tomorrow.setDate(tomorrow.getDate() + 1);
100-
expect(nextRunAt.getUTCDay()).toBe(tomorrow.getUTCDay());
101-
}
102-
expect(nextRunAt.getUTCHours()).toBe(12);
103-
expect(nextRunAt.getUTCMinutes()).toBe(15);
104-
expect(nextRunAt.getUTCSeconds()).toBe(currentSecond);
105-
expect(nextRunAt.getUTCMilliseconds()).toBe(currentMilliseconds);
92+
test('should use the rrule with a fixed time when it is given to calculate the next runAt (next day)', () => {
93+
const now = new Date('2025-06-30T13:00:00.000Z');
94+
const testStart = new Date(now.getTime() - 500);
95+
const testRunAt = new Date(now.getTime() - 1000);
96+
const nextRunAt = getNextRunAt(
97+
taskManagerMock.createTask({
98+
schedule: {
99+
rrule: {
100+
freq: 3, // Daily
101+
interval: 1,
102+
tzid: 'UTC',
103+
byhour: [12],
104+
byminute: [15],
105+
},
106+
},
107+
runAt: testRunAt,
108+
startedAt: testStart,
109+
}),
110+
0,
111+
mockLogger
112+
);
113+
const expectedNextRunAt = new Date('2025-07-01T12:15:59.500Z');
114+
expect(nextRunAt).toEqual(expectedNextRunAt);
106115
});
107116

108117
test('should use the rrule with a basic interval time when it is given to calculate the next runAt', () => {

0 commit comments

Comments
 (0)