Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-13237-tests-1767269372512.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Fix flaky CI failures by removing invalid UI-to-UTC time comparisons in metrics tests ([#13237](https://github.com/linode/manager/pull/13237))
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,16 @@ const databaseMock: Database = databaseFactory.build({
region: mockRegion.id,
type: engine,
});
// Profile timezone is set to 'UTC'

const timezone = 'America/New_York';
// Profile timezone is set to 'America/New_York'
const mockProfile = profileFactory.build({
timezone: 'UTC',
timezone,
});
/**
* Generates a date in Indian Standard Time (IST) based on a specified number of days offset,
* Generates a date in America/New_York based on a specified number of days offset,
* hour, and minute. The function also provides individual date components such as day, hour,
* minute, month, and AM/PM.
*
* @param {number} daysOffset - The number of days to adjust from the current date. Positive
* values give a future date, negative values give a past date.
* @param {number} hour - The hour to set for the resulting date (0-23).
* @param {number} [minute=0] - The minute to set for the resulting date (0-59). Defaults to 0.
*
Expand All @@ -121,11 +120,11 @@ const getDateRangeInGMT = (
minute: number = 0,
isStart: boolean = false
) => {
const now = DateTime.now().setZone('GMT'); // Set the timezone to GMT
const now = DateTime.now().setZone(timezone);
const targetDate = isStart
? now.startOf('month').set({ hour, minute }).setZone('GMT')
: now.set({ hour, minute }).setZone('GMT');
const actualDate = targetDate.setZone('GMT').toFormat('yyyy-LL-dd HH:mm');
? now.startOf('month').set({ hour, minute }).setZone(timezone)
: now.set({ hour, minute }).setZone(timezone);
const actualDate = targetDate.setZone(timezone).toFormat('yyyy-LL-dd HH:mm');

const previousMonthDate = targetDate.minus({ months: 1 });

Expand All @@ -149,30 +148,23 @@ const getDateRangeInGMT = (
* @returns {{start: string, end: string}} - The start and end dates of the current month in ISO 8601 format.
*/

const getThisMonthRange = (): DateTimeWithPreset => {
const nowUtc = DateTime.utc(); // Current time in UTC

const startOfMonthUtc = nowUtc.startOf('month'); // Start of current month in UTC
const getThisMonthRange = (timeZone: string): DateTimeWithPreset => {
const now = DateTime.now().setZone(timeZone);

return {
start: startOfMonthUtc.toFormat(formatter),
end: nowUtc.toFormat(formatter),
start: now.startOf('month').toUTC().toFormat(formatter),
end: now.toUTC().toFormat(formatter),
};
};
const getLastMonthRange = (): DateTimeWithPreset => {
// Get current time in UTC
const now = DateTime.utc();

// Get last month in UTC
const lastMonth = now.minus({ months: 1 });
const getLastMonthRange = (timeZone: string): DateTimeWithPreset => {
const now = DateTime.now().setZone(timeZone);

// Get start and end of last month in UTC and format
const start = lastMonth.startOf('month').toFormat(formatter);
const end = lastMonth.endOf('month').toFormat(formatter);
const lastMonth = now.minus({ months: 1 });

return {
start,
end,
start: lastMonth.startOf('month').toUTC().toFormat(formatter),
end: lastMonth.endOf('month').toUTC().toFormat(formatter),
};
};

Expand All @@ -193,7 +185,7 @@ describe('Integration tests for verifying Cloudpulse custom and preset configura
* - Mocks user preferences for dashboard details (dashboard, engine, resources, and region).
* - Simulates loading test data without real API calls.
*
* - Creates a mock profile with timezone set to GMT ('Etc/GMT').
* - Creates a mock profile with timezone set to America/New_York.
* - Ensures consistency in time-based functionality and API requests.
*
* - Confirms accurate calculation of "This Month" and "Last Month" time ranges.
Expand Down Expand Up @@ -241,7 +233,6 @@ describe('Integration tests for verifying Cloudpulse custom and preset configura
});

it('should implement and validate custom date/time picker for a specific date and time range', () => {
// --- Generate start and end date/time in GMT ---
const {
actualDate: startActualDate,
day: startDay,
Expand Down Expand Up @@ -522,7 +513,7 @@ describe('Integration tests for verifying Cloudpulse custom and preset configura
});

it('Select the "Last Month" preset from the "Time Range" dropdown and verify its functionality.', () => {
const { end, start } = getLastMonthRange();
const { start, end } = getLastMonthRange(timezone);

ui.button.findByTitle('Last hour').as('startDateInput');
cy.get('@startDateInput').scrollIntoView();
Expand Down Expand Up @@ -558,7 +549,7 @@ describe('Integration tests for verifying Cloudpulse custom and preset configura
});

it('Select the "This Month" preset from the "Time Range" dropdown and verify its functionality.', () => {
const { end, start } = getThisMonthRange();
const { start, end } = getThisMonthRange(timezone);

ui.button.findByTitle('Last hour').as('startDateInput');
cy.get('@startDateInput').scrollIntoView();
Expand Down