fix(site): prevent overwriting of newest workspace data during optimistic updates (#10751)

This commit is contained in:
Bruno Quaresma
2023-11-17 09:13:46 -03:00
committed by GitHub
parent 71f87d054f
commit 4121121797
3 changed files with 14 additions and 9 deletions
+1 -2
View File
@@ -16,7 +16,7 @@ import {
RichParameter,
} from "./provisionerGenerated";
import { prometheusPort, pprofPort } from "./constants";
import { port, TEST_TIMEOUT } from "./playwright.config";
import { port } from "./playwright.config";
import * as ssh from "ssh2";
import { Duplex } from "stream";
import { WorkspaceBuildParameter } from "api/typesGenerated";
@@ -197,7 +197,6 @@ export const stopWorkspace = async (page: Page, workspaceName: string) => {
"span[data-testid='build-status'] >> text=Stopped",
{
state: "visible",
timeout: TEST_TIMEOUT * 2,
},
);
};
+1 -3
View File
@@ -12,8 +12,6 @@ const coderMain = path.join(__dirname, "../../enterprise/cmd/coder");
export const STORAGE_STATE = path.join(__dirname, ".auth.json");
export const TEST_TIMEOUT = 60_000;
const localURL = (port: number, path: string): string => {
return `http://localhost:${port}${path}`;
};
@@ -31,7 +29,7 @@ export default defineConfig({
use: {
storageState: STORAGE_STATE,
},
timeout: TEST_TIMEOUT,
timeout: 60_000,
},
],
reporter: [["./reporter.ts"]],
+12 -4
View File
@@ -249,10 +249,18 @@ const updateWorkspaceBuild = async (
build.workspace_name,
);
const previousData = queryClient.getQueryData(workspaceKey) as Workspace;
queryClient.setQueryData(workspaceKey, {
...previousData,
latest_build: build,
});
// Check if the build returned is newer than the previous build that could be
// updated from web socket
const previousUpdate = new Date(previousData.latest_build.updated_at);
const newestUpdate = new Date(build.updated_at);
if (newestUpdate > previousUpdate) {
queryClient.setQueryData(workspaceKey, {
...previousData,
latest_build: build,
});
}
await queryClient.invalidateQueries({
queryKey: workspaceBuildsKey(build.workspace_id),
});