Skip to content

Commit cfc53fb

Browse files
committed
chore: Add benchmark logs to test
1 parent 8e012e4 commit cfc53fb

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

site/src/pages/TemplateSettingsPage/TemplateSchedulePage/TemplateSchedulePage.test.tsx

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*eslint eslint-comments/disable-enable-pair: error -- Remove after bottlenecks or causes of timeouts for testing have been figured out */
12
import { screen, waitFor } from "@testing-library/react";
23
import userEvent from "@testing-library/user-event";
34
import * as API from "api/api";
@@ -36,49 +37,64 @@ const renderTemplateSchedulePage = async () => {
3637
await waitForLoaderToBeRemoved();
3738
};
3839

40+
// Extracts all properties from TemplateScheduleFormValues that have a key that
41+
// ends in _ms, and makes those properties optional. Defined as mapped type to
42+
// ensure this stays in sync as TemplateScheduleFormValues changes
43+
type FillAndSubmitConfig = {
44+
[Key in keyof TemplateScheduleFormValues as Key extends `${string}_ms`
45+
? Key
46+
: never]?: TemplateScheduleFormValues[Key] | undefined;
47+
};
48+
49+
/*eslint-disable no-console -- Start benchmarks */
3950
const fillAndSubmitForm = async ({
4051
default_ttl_ms,
4152
max_ttl_ms,
4253
failure_ttl_ms,
4354
time_til_dormant_ms,
4455
time_til_dormant_autodelete_ms,
45-
}: {
46-
default_ttl_ms?: number;
47-
max_ttl_ms?: number;
48-
failure_ttl_ms?: number;
49-
time_til_dormant_ms?: number;
50-
time_til_dormant_autodelete_ms?: number;
51-
}) => {
56+
}: FillAndSubmitConfig) => {
57+
console.time("form - full function");
5258
const user = userEvent.setup();
5359

60+
console.time("form - ttl");
5461
if (default_ttl_ms) {
5562
const defaultTtlField = await screen.findByLabelText(
5663
"Default autostop (hours)",
5764
);
5865
await user.clear(defaultTtlField);
5966
await user.type(defaultTtlField, default_ttl_ms.toString());
6067
}
68+
console.timeEnd("form - ttl");
6169

70+
console.time("form - max_ttl");
6271
if (max_ttl_ms) {
6372
const maxTtlField = await screen.findByLabelText("Max lifetime (hours)");
73+
6474
await user.clear(maxTtlField);
6575
await user.type(maxTtlField, max_ttl_ms.toString());
6676
}
77+
console.timeEnd("form - max_ttl");
6778

79+
console.time("form - failure_ttl");
6880
if (failure_ttl_ms) {
6981
const failureTtlField = screen.getByRole("checkbox", {
7082
name: /Failure Cleanup/i,
7183
});
7284
await user.type(failureTtlField, failure_ttl_ms.toString());
7385
}
86+
console.timeEnd("form - failure_ttl");
7487

88+
console.time("form - dormant");
7589
if (time_til_dormant_ms) {
7690
const inactivityTtlField = screen.getByRole("checkbox", {
7791
name: /Dormancy Threshold/i,
7892
});
7993
await user.type(inactivityTtlField, time_til_dormant_ms.toString());
8094
}
95+
console.timeEnd("form - dormant");
8196

97+
console.time("form - auto-delete");
8298
if (time_til_dormant_autodelete_ms) {
8399
const dormancyAutoDeletionField = screen.getByRole("checkbox", {
84100
name: /Dormancy Auto-Deletion/i,
@@ -88,16 +104,24 @@ const fillAndSubmitForm = async ({
88104
time_til_dormant_autodelete_ms.toString(),
89105
);
90106
}
107+
console.timeEnd("form - auto-delete");
91108

109+
console.time("form - submit");
92110
const submitButton = await screen.findByText(
93111
FooterFormLanguage.defaultSubmitLabel,
94112
);
95113
await user.click(submitButton);
114+
console.timeEnd("form - submit");
96115

97-
// User needs to confirm dormancy and autodeletion fields.
116+
console.time("form - confirm");
117+
// User needs to confirm dormancy and auto-deletion fields.
98118
const confirmButton = await screen.findByTestId("confirm-button");
99119
await user.click(confirmButton);
120+
console.timeEnd("form - confirm");
121+
122+
console.timeEnd("form - full function");
100123
};
124+
/*eslint-enable no-console -- End benchmarks */
101125

102126
describe("TemplateSchedulePage", () => {
103127
beforeEach(() => {
@@ -109,15 +133,16 @@ describe("TemplateSchedulePage", () => {
109133
jest.spyOn(API, "getExperiments").mockResolvedValue(["workspace_actions"]);
110134
});
111135

112-
it("succeeds", async () => {
136+
it("Calls the API when user fills in and submits a form", async () => {
113137
await renderTemplateSchedulePage();
114138
jest.spyOn(API, "updateTemplateMeta").mockResolvedValueOnce({
115139
...MockTemplate,
116140
...validFormValues,
117141
});
142+
118143
await fillAndSubmitForm(validFormValues);
119144
await waitFor(() => expect(API.updateTemplateMeta).toBeCalledTimes(1));
120-
});
145+
}, 15_000);
121146

122147
test("default and max ttl is converted to and from hours", async () => {
123148
await renderTemplateSchedulePage();

0 commit comments

Comments
 (0)