From 2efe7f6b5e3ec510f5a31b60e28dc699b14b99cf Mon Sep 17 00:00:00 2001 From: David Crespo Date: Tue, 30 Jun 2026 20:29:46 -0500 Subject: [PATCH] Freeze clock in instance metrics e2e tests to kill midnight flake The date range picker tests derive a default "Last hour" range from the real wall clock, which makes them fail near midnight UTC in two ways: the range straddles the day boundary (fixed defensively in #3269), and the calendar opens on the range start month, so the "Today" cell is missing when the run crosses a month boundary (June 30 -> July 1). Freeze the clock to a fixed mid-month noon so neither depends on when CI runs, and revert the #3269 time-juggling that is no longer needed. --- test/e2e/instance-metrics.e2e.ts | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/test/e2e/instance-metrics.e2e.ts b/test/e2e/instance-metrics.e2e.ts index 46577fe18..071b2531b 100644 --- a/test/e2e/instance-metrics.e2e.ts +++ b/test/e2e/instance-metrics.e2e.ts @@ -12,6 +12,14 @@ import { OXQL_GROUP_BY_ERROR } from '~/api' import { expectConsoleMessage, expectNoConsoleMessage, getPageAsUser } from './utils' +// Freeze the clock so the default "Last hour" range and the calendar's visible +// month don't depend on when the tests run. Without this, runs near midnight +// UTC flake: the range straddles the day boundary, and on a month boundary the +// calendar opens on the previous month, so the "Today" cell isn't rendered. +test.beforeEach(async ({ page }) => { + await page.clock.setFixedTime(new Date('2026-06-15T12:00:00.000Z')) +}) + test('Click through instance metrics', async ({ page }) => { await page.goto('/projects/mock-project/instances/db1/metrics/cpu') @@ -76,31 +84,19 @@ test('Date range picker: invalid range shows an error', async ({ page }) => { const today = page.getByRole('button', { name: /Today/ }) await today.click() await today.click() + await expect(page.getByText('Date range is invalid')).toBeHidden() - // Set the times explicitly rather than relying on the times inherited from - // the default "Last hour" range. When the test runs shortly after midnight, - // that range straddles midnight (start ~23:00 the previous day, end ~00:00 - // today), so collapsing both dates to today leaves start after end and the - // range reads as invalid before we've done anything. Start with a valid - // same-day range (01:00 before 23:00): no error. + // set the start time (23:00) after the end time (01:00) on that same day const hours = page.getByRole('spinbutton', { name: 'hour,' }) const minutes = page.getByRole('spinbutton', { name: 'minute,' }) await hours.first().click() - await page.keyboard.type('01') + await page.keyboard.type('23') await minutes.first().click() await page.keyboard.type('00') await hours.nth(1).click() - await page.keyboard.type('23') + await page.keyboard.type('01') await minutes.nth(1).click() await page.keyboard.type('00') - await expect(page.getByText('Date range is invalid')).toBeHidden() - - // now flip the start time (23:00) to be after the end time (01:00) on that - // same day - await hours.first().click() - await page.keyboard.type('23') - await hours.nth(1).click() - await page.keyboard.type('01') await expect(page.getByText('Date range is invalid')).toBeVisible() })