Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instance state changes asynchronously in mock API #2167

Merged
merged 2 commits into from
Apr 19, 2024
Merged
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
26 changes: 22 additions & 4 deletions mock-api/msw/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down Expand Up @@ -599,7 +609,7 @@ export const handlers = makeHandlers({

setTimeout(() => {
instance.run_state = 'running'
}, 3000)
}, 1000)

return json(instance, { status: 202 })
},
Expand All @@ -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'
}, 1000)

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'
}, 1000)

return json(instance, { status: 202 })
},
Expand Down
8 changes: 7 additions & 1 deletion test/e2e/instance.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()

Expand All @@ -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()
})

Expand Down
12 changes: 3 additions & 9 deletions test/e2e/network-interface-create.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
13 changes: 10 additions & 3 deletions test/e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

/**
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/z-index.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Loading