From fa83a1b9fc09a4c548744b89cea580fdce7695a7 Mon Sep 17 00:00:00 2001 From: David Crespo Date: Thu, 18 Apr 2024 15:35:04 -0500 Subject: [PATCH 1/2] add delays, some tests fail --- mock-api/msw/handlers.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/mock-api/msw/handlers.ts b/mock-api/msw/handlers.ts index 2135de0f89..64219da4c4 100644 --- a/mock-api/msw/handlers.ts +++ b/mock-api/msw/handlers.ts @@ -474,10 +474,20 @@ export const handlers = makeHandlers({ project_id: project.id, ...pick(body, 'name', 'description', 'hostname', 'memory', 'ncpus'), ...getTimestamps(), - run_state: 'running', + run_state: 'creating', time_run_state_updated: new Date().toISOString(), } + + setTimeout(() => { + newInstance.run_state = 'starting' + }, 1000) + + setTimeout(() => { + newInstance.run_state = 'running' + }, 5000) + db.instances.push(newInstance) + return json(newInstance, { status: 201 }) }, instanceView: ({ path, query }) => lookup.instance({ ...path, ...query }), @@ -609,13 +619,21 @@ export const handlers = makeHandlers({ }, instanceStart({ path, query }) { const instance = lookup.instance({ ...path, ...query }) - instance.run_state = 'running' + instance.run_state = 'starting' + + setTimeout(() => { + instance.run_state = 'running' + }, 3000) return json(instance, { status: 202 }) }, instanceStop({ path, query }) { const instance = lookup.instance({ ...path, ...query }) - instance.run_state = 'stopped' + instance.run_state = 'stopping' + + setTimeout(() => { + instance.run_state = 'stopped' + }, 3000) return json(instance, { status: 202 }) }, From c33bf01805628fd798f03c351e50800e82002265 Mon Sep 17 00:00:00 2001 From: David Crespo Date: Thu, 18 Apr 2024 22:40:28 -0500 Subject: [PATCH 2/2] make the tests pass --- mock-api/msw/handlers.ts | 6 +++--- test/e2e/instance.e2e.ts | 8 +++++++- test/e2e/network-interface-create.e2e.ts | 12 +++--------- test/e2e/utils.ts | 13 ++++++++++--- test/e2e/z-index.e2e.ts | 7 ++----- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/mock-api/msw/handlers.ts b/mock-api/msw/handlers.ts index 64219da4c4..f755c8526a 100644 --- a/mock-api/msw/handlers.ts +++ b/mock-api/msw/handlers.ts @@ -609,7 +609,7 @@ export const handlers = makeHandlers({ setTimeout(() => { instance.run_state = 'running' - }, 3000) + }, 1000) return json(instance, { status: 202 }) }, @@ -623,7 +623,7 @@ export const handlers = makeHandlers({ setTimeout(() => { instance.run_state = 'running' - }, 3000) + }, 1000) return json(instance, { status: 202 }) }, @@ -633,7 +633,7 @@ export const handlers = makeHandlers({ setTimeout(() => { instance.run_state = 'stopped' - }, 3000) + }, 1000) return json(instance, { status: 202 }) }, diff --git a/test/e2e/instance.e2e.ts b/test/e2e/instance.e2e.ts index 09a2c137d6..3fc9a3c68f 100644 --- a/test/e2e/instance.e2e.ts +++ b/test/e2e/instance.e2e.ts @@ -5,7 +5,7 @@ * * Copyright Oxide Computer Company */ -import { expect, test } from './utils' +import { expect, refreshInstance, sleep, test } from './utils' test('can delete a failed instance', async ({ page }) => { await page.goto('/projects/mock-project/instances') @@ -36,6 +36,9 @@ test('can stop and delete a running instance', async ({ page }) => { await page.getByRole('menuitem', { name: 'Stop' }).click() await page.getByRole('button', { name: 'Confirm' }).click() + await sleep(3000) + await refreshInstance(page) + // now it's stopped await expect(row.getByRole('cell', { name: /stopped/ })).toBeVisible() @@ -58,6 +61,9 @@ test('can stop a starting instance', async ({ page }) => { await page.getByRole('menuitem', { name: 'Stop' }).click() await page.getByRole('button', { name: 'Confirm' }).click() + await sleep(3000) + await refreshInstance(page) + await expect(row.getByRole('cell', { name: /stopped/ })).toBeVisible() }) diff --git a/test/e2e/network-interface-create.e2e.ts b/test/e2e/network-interface-create.e2e.ts index cdcc8f8b65..6fa1193112 100644 --- a/test/e2e/network-interface-create.e2e.ts +++ b/test/e2e/network-interface-create.e2e.ts @@ -7,16 +7,13 @@ */ import { test } from '@playwright/test' -import { expect, expectRowVisible } from './utils' +import { expect, expectRowVisible, stopInstance } from './utils' test('can create a NIC with a specified IP address', async ({ page }) => { // go to an instance’s Network Interfaces page await page.goto('/projects/mock-project/instances/db1/network-interfaces') - // stop the instance - await page.getByRole('button', { name: 'Instance actions' }).click() - await page.getByRole('menuitem', { name: 'Stop' }).click() - await page.getByRole('button', { name: 'Confirm' }).click() + await stopInstance(page) // open the add network interface side modal await page.getByRole('button', { name: 'Add network interface' }).click() @@ -43,10 +40,7 @@ test('can create a NIC with a blank IP address', async ({ page }) => { // go to an instance’s Network Interfaces page await page.goto('/projects/mock-project/instances/db1/network-interfaces') - // stop the instance - await page.getByRole('button', { name: 'Instance actions' }).click() - await page.getByRole('menuitem', { name: 'Stop' }).click() - await page.getByRole('button', { name: 'Confirm' }).click() + await stopInstance(page) // open the add network interface side modal await page.getByRole('button', { name: 'Add network interface' }).click() diff --git a/test/e2e/utils.ts b/test/e2e/utils.ts index 8cf2419bb0..13f7e6beda 100644 --- a/test/e2e/utils.ts +++ b/test/e2e/utils.ts @@ -104,10 +104,17 @@ export async function expectRowVisible( } export async function stopInstance(page: Page) { - await page.click('role=button[name="Instance actions"]') - await page.click('role=menuitem[name="Stop"]') - await page.click('role=button[name="Confirm"]') + await page.getByRole('button', { name: 'Instance actions' }).click() + await page.getByRole('menuitem', { name: 'Stop' }).click() + await page.getByRole('button', { name: 'Confirm' }).click() await closeToast(page) + await sleep(1200) + await refreshInstance(page) + await expect(page.getByText('statusstopped')).toBeVisible() +} + +export async function refreshInstance(page: Page) { + await page.getByRole('button', { name: 'Refresh data' }).click() } /** diff --git a/test/e2e/z-index.e2e.ts b/test/e2e/z-index.e2e.ts index ae764869ec..6f33157c29 100644 --- a/test/e2e/z-index.e2e.ts +++ b/test/e2e/z-index.e2e.ts @@ -7,7 +7,7 @@ */ import { expect, test } from '@playwright/test' -import { expectObscured } from './utils' +import { expectObscured, stopInstance } from './utils' test('Dropdown content can scroll off page and doesn’t hide TopBar', async ({ page }) => { // load the page @@ -45,10 +45,7 @@ test('Dropdown content in SidebarModal shows on screen', async ({ page }) => { // go to an instance’s Network Interfaces page await page.goto('/projects/mock-project/instances/db1/network-interfaces') - // stop the instance - await page.getByRole('button', { name: 'Instance actions' }).click() - await page.getByRole('menuitem', { name: 'Stop' }).click() - await page.getByRole('button', { name: 'Confirm' }).click() + await stopInstance(page) // open the add network interface side modal await page.getByRole('button', { name: 'Add network interface' }).click()