-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathinstance-auto-restart.e2e.ts
More file actions
168 lines (133 loc) · 6.99 KB
/
instance-auto-restart.e2e.ts
File metadata and controls
168 lines (133 loc) · 6.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright Oxide Computer Company
*/
import { expect, test } from '@playwright/test'
import { expectToast } from './utils'
test('Auto restart policy on failed instance', async ({ page }) => {
await page.goto('/projects/mock-project/instances/you-fail')
// check popover
const indicator = page.getByRole('button', { name: 'Auto-restart status' })
await indicator.click()
await expect(page.getByText('Auto RestartEnabled')).toBeVisible()
await expect(page.getByText('PolicyDefault')).toBeVisible()
await expect(page.getByText('CooldownWaiting (5 minutes)')).toBeVisible()
// now go to settings tab by clicking link in popover
await page.getByRole('link', { name: 'Default' }).click()
// assert contents of table-like thing showing the state. leave date underspecified
// because it's always 5 minutes of whatever now is
await expect(page.getByText(/Cooldown expiration.+, 202\d.+\(5 minutes\)/)).toBeVisible()
await expect(page.getByText(/Last auto-restarted.+, 202\d/)).toBeVisible()
// Scope to the Auto-restart card to avoid ambiguity with other Save buttons
const autoRestartSection = page.locator('form', {
has: page.getByRole('heading', { name: 'Auto-restart' }),
})
const save = autoRestartSection.getByRole('button', { name: 'Save' })
const policyListbox = autoRestartSection.getByRole('button', { name: 'Policy' })
await expect(save).toBeDisabled()
await expect(policyListbox).toContainText('Default')
await policyListbox.click()
await page.getByRole('option', { name: 'Never' }).click()
await save.click()
await expectToast(page, 'Instance auto-restart policy updated')
await expect(policyListbox).toContainText('Never')
await expect(save).toBeDisabled()
})
// unlike the other instance update things, you can change auto restart policy
// regardless of state
test('Auto restart policy on running instance', async ({ page }) => {
await page.goto('/projects/mock-project/instances/db1')
await expect(page.getByText('Running')).toBeVisible() // it's running. we know
// go to settings tab
await page.getByRole('tab', { name: 'settings' }).click()
// assert contents of table-like thing showing the state
await expect(page.getByText('Cooldown expirationN/A')).toBeVisible()
await expect(page.getByText('Last auto-restartedN/A')).toBeVisible()
// Scope to the Auto-restart card to avoid ambiguity with other Save buttons
const autoRestartSection = page.locator('form', {
has: page.getByRole('heading', { name: 'Auto-restart' }),
})
const save = autoRestartSection.getByRole('button', { name: 'Save' })
const policyListbox = autoRestartSection.getByRole('button', { name: 'Policy' })
await expect(save).toBeDisabled()
await expect(policyListbox).toContainText('Default')
await policyListbox.click()
await page.getByRole('option', { name: 'Never' }).click()
await save.click()
await expectToast(page, 'Instance auto-restart policy updated')
await expect(policyListbox).toContainText('Never')
await expect(save).toBeDisabled()
})
test('Auto restart popover, restarting soon', async ({ page }) => {
await page.goto('/projects/other-project/instances/failed-restarting-soon')
// check popover
const indicator = page.getByRole('button', { name: 'Auto-restart status' })
await indicator.click()
await expect(page.getByText('Auto RestartEnabled')).toBeVisible()
await expect(page.getByText('PolicyDefault')).toBeVisible()
await expect(page.getByText('Restarting soon…')).toBeVisible()
await expect(page.getByText('instance will automatically restart soon')).toBeVisible()
// go to settings tab
await page.getByRole('link', { name: 'Default' }).click()
// assert contents of table-like thing showing the state
await expect(
page.getByText(/Cooldown expiration.+, 202\d.+\(restarting soon\)/)
).toBeVisible()
await expect(page.getByText(/Last auto-restarted.+, 202\d/)).toBeVisible()
// Scope to the Auto-restart card to avoid ambiguity with other Save buttons
const autoRestartSection = page.locator('form', {
has: page.getByRole('heading', { name: 'Auto-restart' }),
})
const policyListbox = autoRestartSection.getByRole('button', { name: 'Policy' })
const save = autoRestartSection.getByRole('button', { name: 'Save' })
await expect(policyListbox).toContainText('Default')
await expect(save).toBeDisabled()
})
test('Auto restart popover, policy never', async ({ page }) => {
await page.goto('/projects/other-project/instances/failed-restart-never')
// check popover
const indicator = page.getByRole('button', { name: 'Auto-restart status' })
await indicator.click()
await expect(page.getByText('Auto RestartDisabled')).toBeVisible()
await expect(page.getByText('PolicyNever')).toBeVisible()
await expect(page.getByText('Cooldown')).toBeHidden()
await expect(page.getByText('instance will not automatically restart')).toBeVisible()
// go to settings tab
await page.getByRole('link', { name: 'never', exact: true }).click()
await expect(page.getByText(/Cooldown expiration.+, 202\d.+/)).toBeVisible()
await expect(page.getByText(/Last auto-restarted.+, 202\d/)).toBeVisible()
// Scope to the Auto-restart card to avoid ambiguity with other Save buttons
const autoRestartSection = page.locator('form', {
has: page.getByRole('heading', { name: 'Auto-restart' }),
})
const policyListbox = autoRestartSection.getByRole('button', { name: 'Policy' })
const save = autoRestartSection.getByRole('button', { name: 'Save' })
await expect(policyListbox).toContainText('Never')
await expect(save).toBeDisabled()
})
test('Auto restart popover, cooled, policy never, cooled', async ({ page }) => {
await page.goto('/projects/other-project/instances/failed-cooled-restart-never')
// check popover
const indicator = page.getByRole('button', { name: 'Auto-restart status' })
await indicator.click()
await expect(page.getByText('Auto RestartDisabled')).toBeVisible()
await expect(page.getByText('PolicyNever')).toBeVisible()
await expect(page.getByText('Cooldown')).toBeHidden()
await expect(page.getByText('instance will not automatically restart')).toBeVisible()
// go to settings tab
await page.getByRole('link', { name: 'never', exact: true }).click()
await expect(page.getByText(/Cooldown expiration.+, 202\d.+/)).toBeVisible()
await expect(page.getByText('restarting soon')).toBeHidden()
await expect(page.getByText(/Last auto-restarted.+, 202\d/)).toBeVisible()
// Scope to the Auto-restart card to avoid ambiguity with other Save buttons
const autoRestartSection = page.locator('form', {
has: page.getByRole('heading', { name: 'Auto-restart' }),
})
const policyListbox = autoRestartSection.getByRole('button', { name: 'Policy' })
const save = autoRestartSection.getByRole('button', { name: 'Save' })
await expect(policyListbox).toContainText('Never')
await expect(save).toBeDisabled()
})