Skip to content

Commit e0ec01d

Browse files
authored
Fix memory queue with deduplication and add basic test app (#480)
* deduplicate using MessageDeduplicationId * add test app for the memory-queue * small improvement to the memory-queue * linting * fix missing .js * review * fix flaky test
1 parent bdf74de commit e0ec01d

File tree

18 files changed

+348
-34
lines changed

18 files changed

+348
-34
lines changed

.changeset/friendly-experts-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fix deduplication for memory queue and add some log

examples/common/apps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const apps = [
1414
"pages-router",
1515
// overrides
1616
"d1-tag-next",
17+
"memory-queue",
1718
// bugs
1819
"gh-119",
1920
"gh-219",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
.pnpm-debug.log*
32+
33+
# env files (can opt-in for committing if needed)
34+
.env*
35+
36+
# vercel
37+
.vercel
38+
39+
# typescript
40+
*.tsbuildinfo
41+
next-env.d.ts
42+
43+
# playwright
44+
/test-results/
45+
/playwright-report/
46+
/blob-report/
47+
/playwright/.cache/
25.3 KB
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
html,
2+
body {
3+
max-width: 100vw;
4+
overflow-x: hidden;
5+
height: 100vh;
6+
display: flex;
7+
flex-direction: column;
8+
}
9+
10+
footer {
11+
padding: 1rem;
12+
display: flex;
13+
justify-content: end;
14+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { Metadata } from "next";
2+
import "./globals.css";
3+
4+
import { getCloudflareContext } from "@opennextjs/cloudflare";
5+
6+
export const metadata: Metadata = {
7+
title: "SSG App",
8+
description: "An app in which all the routes are SSG'd",
9+
};
10+
11+
export default async function RootLayout({
12+
children,
13+
}: Readonly<{
14+
children: React.ReactNode;
15+
}>) {
16+
const cloudflareContext = await getCloudflareContext({
17+
async: true,
18+
});
19+
20+
return (
21+
<html lang="en">
22+
<body>{children}</body>
23+
</html>
24+
);
25+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.page {
2+
display: grid;
3+
grid-template-rows: 20px 1fr 20px;
4+
align-items: center;
5+
justify-items: center;
6+
flex: 1;
7+
border: 3px solid gray;
8+
margin: 1rem;
9+
margin-block-end: 0;
10+
}
11+
12+
.main {
13+
display: flex;
14+
flex-direction: column;
15+
gap: 32px;
16+
grid-row-start: 2;
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import styles from "./page.module.css";
2+
3+
export const revalidate = 5;
4+
5+
export default async function Home() {
6+
// We purposefully wait for 2 seconds to allow deduplication to occur
7+
await new Promise((resolve) => setTimeout(resolve, 2000));
8+
return (
9+
<div className={styles.page}>
10+
<main className={styles.main}>
11+
<h1>Hello from a Statically generated page</h1>
12+
<p data-testid="date-local">{Date.now()}</p>
13+
</main>
14+
</div>
15+
);
16+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test.describe("memory-queue", () => {
4+
test("the index page should work", async ({ page }) => {
5+
await page.goto("/");
6+
await expect(page.getByText("Hello from a Statically generated page")).toBeVisible();
7+
});
8+
9+
test("the index page should revalidate", async ({ page, request }) => {
10+
// We need to make sure the page is loaded and is a HIT
11+
// If it is STALE, the next hit may have an updated date and thus fail the test
12+
let cacheHeaders = "";
13+
do {
14+
const req = await request.get("/");
15+
cacheHeaders = req.headers()["x-nextjs-cache"];
16+
await page.waitForTimeout(500);
17+
} while (cacheHeaders !== "HIT");
18+
19+
await page.goto("/");
20+
const firstDate = await page.getByTestId("date-local").textContent();
21+
22+
await page.reload();
23+
let newDate = await page.getByTestId("date-local").textContent();
24+
expect(newDate).toBe(firstDate);
25+
26+
await page.waitForTimeout(5000);
27+
28+
do {
29+
await page.reload();
30+
newDate = await page.getByTestId("date-local").textContent();
31+
await page.waitForTimeout(1000);
32+
} while (newDate === firstDate);
33+
34+
expect(newDate).not.toBe(firstDate);
35+
});
36+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { configurePlaywright } from "../../../common/config-e2e";
2+
3+
// Here we don't want to run the tests in parallel
4+
export default configurePlaywright("memory-queue", {
5+
isCI: !!process.env.CI,
6+
parallel: false,
7+
multipleBrowsers: false,
8+
});

0 commit comments

Comments
 (0)