Skip to content

Modern Docker Management, Designed for Everyone

chore: hopefully fix this flaky test

Kyle Mendell9d27c50c484e
diff --git a/frontend/src/lib/components/action-buttons.svelte b/frontend/src/lib/components/action-buttons.svelte
index 3dc66ccde..761ef01c0 100644
--- a/frontend/src/lib/components/action-buttons.svelte
+++ b/frontend/src/lib/components/action-buttons.svelte
@@ -315,17 +315,13 @@
setLoading('start', true);
try {
- projectService
- .deployProject(id, () => {}, options ?? deployOptionsStore.getRequestOptions())
- .then(async () => {
- await invalidateAll();
- itemState = 'running';
- onActionComplete('running');
- })
- .catch((e: any) => {
- const message = e?.message || m.common_action_failed_with_type({ action: m.common_start(), type });
- toast.error(message);
- });
+ await projectService.deployProject(id, () => {}, options ?? deployOptionsStore.getRequestOptions());
+ await invalidateAll();
+ itemState = 'running';
+ onActionComplete('running');
+ } catch (e: any) {
+ const message = e?.message || m.common_action_failed_with_type({ action: m.common_start(), type });
+ toast.error(message);
} finally {
setLoading('start', false);
}
diff --git a/tests/spec/project.spec.ts b/tests/spec/project.spec.ts
index 1cfdcf1cc..3def7746b 100644
--- a/tests/spec/project.spec.ts
+++ b/tests/spec/project.spec.ts
@@ -1,5 +1,6 @@
import { test, expect, type Locator, type Page, type Response } from '@playwright/test';
import { fetchProjectCountsWithRetry, fetchProjectsWithRetry } from '../utils/fetch.util';
+import type { Activity } from '../types/activity.type';
import { Project, ProjectStatusCounts } from 'types/project.type';
import { TEST_COMPOSE_YAML, TEST_ENV_FILE } from '../setup/project.data';
@@ -99,6 +100,45 @@ async function fetchProjectDetail(page: Page, projectId: string): Promise<Projec
return body as Project;
}
+async function fetchLatestProjectDeployActivity(
+ page: Page,
+ projectId: string
+): Promise<Activity | null> {
+ const params = new URLSearchParams({
+ type: 'project_deploy',
+ resourceType: 'project',
+ search: projectId,
+ limit: '10'
+ });
+ const res = await page.request.get(`/api/environments/0/activities?${params.toString()}`);
+ if (!res.ok()) {
+ return null;
+ }
+
+ const body = await res.json().catch(() => null as any);
+ const activities = (body?.data ?? []) as Activity[];
+ return (
+ activities.find(
+ (activity) =>
+ activity.type === 'project_deploy' &&
+ activity.resourceType === 'project' &&
+ (activity.resourceId === projectId || activity.resourceName === projectId)
+ ) ?? null
+ );
+}
+
+async function expectProjectDeployActivitySucceeded(page: Page, projectId: string) {
+ await expect
+ .poll(
+ async () => (await fetchLatestProjectDeployActivity(page, projectId))?.status ?? 'missing',
+ {
+ message: 'Expected project deploy activity to complete before reload',
+ timeout: 60000
+ }
+ )
+ .toBe('success');
+}
+
async function findProjectWithDetailUpdateAction(page: Page): Promise<Project | null> {
for (const project of realProjects) {
if (Number(project.serviceCount ?? 0) <= 0) {
@@ -678,6 +718,10 @@ test.describe('New Compose Project Page', () => {
timeout: 60000
})
.toBe('running');
+ await expectProjectDeployActivitySucceeded(page, projectId);
+ await expect(page.getByRole('button', { name: 'Down', exact: true })).toBeVisible({
+ timeout: 30000
+ });
expect(projectPullRequestCount).toBe(0);
const projectReloadResponse = page.waitForResponse(
diff --git a/tests/types/activity.type.ts b/tests/types/activity.type.ts
new file mode 100644
index 000000000..a7d4e7a90
--- /dev/null
+++ b/tests/types/activity.type.ts
@@ -0,0 +1,10 @@
+export type ActivityStatus = 'queued' | 'running' | 'success' | 'failed' | 'cancelled';
+
+export type Activity = {
+ id: string;
+ type: string;
+ status: ActivityStatus;
+ resourceType?: string;
+ resourceId?: string;
+ resourceName?: string;
+};