Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add checks of uploads of very large number of Pages assets #6010

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions packages/wrangler/src/__tests__/pages/project-upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,67 @@ describe("pages project upload", () => {
`);
});

it("should handle a very large number of assets", async () => {
const assets = new Set<string>();
// Create a large number of asset files to upload
for (let i = 0; i < 10_019; i++) {
const path = `file-${i}.txt`;
const content = `contents of file-${i}.txt`;
assets.add(content);
writeFileSync(path, content);
CarmenPopoviciu marked this conversation as resolved.
Show resolved Hide resolved
}

mockGetUploadTokenRequest(
"<<funfetti-auth-jwt>>",
"some-account-id",
"foo"
);

// Accumulate multiple requests then assert afterwards
const uploadedAssets = new Set<string>();
msw.use(
http.post("*/pages/assets/check-missing", async ({ request }) => {
const body = (await request.json()) as { hashes: string[] };

return HttpResponse.json(
{
success: true,
errors: [],
messages: [],
result: body.hashes,
},
{ status: 200 }
);
}),
http.post<never, UploadPayloadFile[]>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how many times do we expect this endpoint to be called? should we assert that as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other tests that check how the bucketing works and exactly what requests are made.
This test is purely looking at whether the correct number of assets arrive at the server or not.

"*/pages/assets/upload",
async ({ request }) => {
const body = await request.json();
// Capture the assets that are uploaded
for (const asset of body) {
uploadedAssets.add(
Buffer.from(asset.value, "base64").toString("utf8")
);
}

return HttpResponse.json(
{
success: true,
errors: [],
messages: [],
result: null,
},
{ status: 200 }
);
}
)
);

await runWrangler("pages project upload .");

expect(uploadedAssets).toEqual(assets);
});

it("should not error when directory names contain periods and houses a extensionless file", async () => {
mkdirSync(".well-known");
// Note: same content as previous test, but since it's a different extension,
Expand Down
Loading