Skip to content

Commit 04bfec5

Browse files
committed
copy tweaks, fill in tests
1 parent 690b788 commit 04bfec5

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

app/pages/project/instances/instance/InstancePage.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ InstancePage.loader = async ({ params }: LoaderFunctionArgs) => {
109109

110110
const POLL_INTERVAL = 1000
111111

112+
// We're using this logic here on instance detail, but not on instance list.
113+
// Instance list will only poll for the transitioning case. We don't show
114+
// anything about cooldown on the instance list, so the only point of polling
115+
// would be to catch a restart when it happens. But with the cooldown period
116+
// being an hour, we'd be doing a _lot_ of unnecessary polling on the list page.
112117
function shouldPoll(instance: Instance) {
113118
if (instanceTransitioning(instance)) return 'transition'
114119
if (instanceCoolingDown(instance)) return 'cooldown'

app/pages/project/instances/instance/tabs/SettingsTab.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,13 @@ export function Component() {
9898
name="autoRestartPolicy"
9999
label="Policy"
100100
description="The global default is currently best effort, but this may change in the future."
101-
placeholder="Default"
102101
items={restartPolicyItems}
103102
required
104103
className="max-w-none"
105104
/>
106105
<FormMeta
107106
label="Cooldown expiration"
108-
helpText="The time at which the auto-restart cooldown period for this instance completes. If N/A, then either the instance has never been automatically restarted, or the cooldown period has already expired."
107+
helpText="When this instance will next restart (if in a failed state and the policy allows it). If N/A, then either the instance has never been automatically restarted, or the cooldown period has expired."
109108
>
110109
{
111110
// TODO: show preview of how the time would change on update when
@@ -126,10 +125,10 @@ export function Component() {
126125
</FormMeta>
127126
<FormMeta
128127
label="Last auto-restarted"
129-
helpText="When this instance was last automatically restarted. Empty if never auto-restarted."
128+
helpText="When this instance was last automatically restarted. N/A if never auto-restarted."
130129
>
131130
{instance.timeLastAutoRestarted ? (
132-
<>{toLocaleDateTimeString(instance.timeLastAutoRestarted)}</>
131+
toLocaleDateTimeString(instance.timeLastAutoRestarted)
133132
) : (
134133
<span className="text-tertiary">N/A</span>
135134
)}

test/e2e/instance-auto-restart.e2e.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { expect, test } from '@playwright/test'
99

1010
import { expectToast } from './utils'
1111

12-
test('Instance auto restart policy', async ({ page }) => {
12+
test('Auto restart policy on failed instance', async ({ page }) => {
1313
await page.goto('/projects/mock-project/instances/you-fail')
1414

1515
// check popover
@@ -22,9 +22,11 @@ test('Instance auto restart policy', async ({ page }) => {
2222
// now go to settings tab by clicking link in popover
2323
await page.getByRole('link', { name: 'Default' }).click()
2424

25-
// assert contents of table-like thing showing the state
25+
// assert contents of table-like thing showing the state. leave date underspecified
26+
// because it's always 5 minutes of whatever now is
27+
await expect(page.getByText(/Cooldown expiration.+, 202\d.+\(5 minutes\)/)).toBeVisible()
28+
await expect(page.getByText(/Last auto-restarted.+, 202\d/)).toBeVisible()
2629

27-
// await expect(page.getByRole('button', { name: 'Policy' }))
2830
const save = page.getByRole('button', { name: 'Save' })
2931
await expect(save).toBeDisabled()
3032

@@ -37,7 +39,37 @@ test('Instance auto restart policy', async ({ page }) => {
3739

3840
await expectToast(page, 'Instance auto-restart policy updated')
3941
await expect(policyListbox).toContainText('Never')
42+
await expect(save).toBeDisabled()
4043
})
4144

4245
// TODO: test that polling updates the relevant stuff
43-
// TODO: test updating policy on a running instance
46+
47+
// unlike the other instance update things, you can change auto restart policy
48+
// regardless of state
49+
test('Auto restart policy on running instance', async ({ page }) => {
50+
await page.goto('/projects/mock-project/instances/db1')
51+
52+
await expect(page.getByText('Running')).toBeVisible() // it's running. we know
53+
54+
// go to settings tab
55+
await page.getByRole('tab', { name: 'settings' }).click()
56+
57+
// assert contents of table-like thing showing the state
58+
await expect(page.getByText('Cooldown expirationN/A')).toBeVisible()
59+
await expect(page.getByText('Last auto-restartedN/A')).toBeVisible()
60+
61+
// await expect(page.getByRole('button', { name: 'Policy' }))
62+
const save = page.getByRole('button', { name: 'Save' })
63+
await expect(save).toBeDisabled()
64+
65+
const policyListbox = page.getByRole('button', { name: 'Policy' })
66+
await expect(policyListbox).toContainText('Default')
67+
68+
await page.getByRole('button', { name: 'Policy' }).click()
69+
await page.getByRole('option', { name: 'Never' }).click()
70+
await save.click()
71+
72+
await expectToast(page, 'Instance auto-restart policy updated')
73+
await expect(policyListbox).toContainText('Never')
74+
await expect(save).toBeDisabled()
75+
})

0 commit comments

Comments
 (0)