Skip to content

Commit

Permalink
Extract perf tests from unit.
Browse files Browse the repository at this point in the history
  • Loading branch information
bstopp committed Aug 19, 2024
1 parent 43aeb0f commit aaa9a26
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 66 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"lint": "eslint .",
"test": "c8 mocha --spec=test/**/*.test.js && mocha --spec=test/it/**/*.spec.js",
"test:unit": "c8 mocha --spec=test/**/*.test.js",
"test:perf": "mocha --spec=test/**/*.perf.js",
"test:it": "mocha --spec=test/it/**/*.spec.js",
"dev": "wrangler dev --env dev",
"deploy:prod": "wrangler deploy",
Expand Down
98 changes: 98 additions & 0 deletions test/storage/object/copy.perf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import assert from 'node:assert';

import { destroyMiniflare, getMiniflare } from '../../mocks/miniflare.js';

import copyObject from '../../../src/storage/object/copy.js';

describe('Object copy', () => {
let mf;
let env;
beforeEach(async () => {
mf = await getMiniflare();
env = await mf.getBindings();
});

afterEach(async function() {
this.timeout(60000);
await destroyMiniflare(mf);
});


describe('copy performance', () => {
const limit = 10000;
beforeEach(async function() {
this.timeout(60000);
// Prep the content.
for (let i = 0; i < limit; i += 100) {
for (let j = 0; j < 100; j++) {
const promises = [];
promises.push(env.DA_CONTENT.put(`wknd/pages/index${i + j}.html`, 'content'));
await Promise.all(promises);
}
}
});

it(`copy handles ${limit} files in folder`, async function() {
this.timeout(60000);
const daCtx = { org: 'wknd', users: [{ email: "[email protected]" }] };
await env.DA_CONTENT.put('wknd.props', '{"key":"value"}');
const details = { source: 'pages', destination: 'pages-newdir' };
const resp = await copyObject(env, daCtx, details);
assert.strictEqual(resp.status, 204);
const head = await env.DA_CONTENT.head('wknd/pages-newdir/index1.html');
assert(head);
});
});

describe('rename performance', () => {

const limit = 10000;
beforeEach(async function() {
this.timeout(60000);
// Prep the content.
for (let i = 0; i < limit; i += 100) {
for (let j = 0; j < 100; j++) {
const promises = [];
promises.push(env.DA_CONTENT.put(`wknd/pages/index${i + j}.html`, 'content'));
await Promise.all(promises);
}
}
});

it(`rename handles ${limit} files in folder`, async function() {
this.timeout(60000);

const daCtx = { org: 'wknd', users: [{ email: "[email protected]" }] };
await env.DA_CONTENT.put('wknd.props', '{"key":"value"}');
const details = { source: 'pages', destination: 'pages-newdir' };
const resp = await copyObject(env, daCtx, details, true);
assert.strictEqual(resp.status, 204);

let r2o = await env.DA_CONTENT.list({ prefix: 'wknd/pages/' });
assert.strictEqual(r2o.truncated, false)

let cursor;
let total = 0;
do {
r2o = await env.DA_CONTENT.list({ prefix: 'wknd/pages-newdir/', cursor });
total += r2o.objects.length;
cursor = r2o.cursor;
} while (r2o.truncated);

assert.deepStrictEqual(total, limit);
let renamed = await env.DA_CONTENT.head('wknd/pages-newdir/index1.html');
assert(renamed);
});
});
});
66 changes: 0 additions & 66 deletions test/storage/object/copy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,6 @@ describe('Object copy', () => {
head = await env.DA_CONTENT.head('wknd/newdir.props');
assert(head);
});

describe('performance', () => {
const limit = 10000;
beforeEach(async function () {
this.timeout(60000);
// Prep the content.
for (let i = 0; i < limit; i += 100) {
for (let j = 0; j < 100; j++) {
const promises = [];
promises.push(env.DA_CONTENT.put(`wknd/pages/index${i+j}.html`, 'content'));
await Promise.all(promises);
}
}
});

it (`copy handles ${limit} files in folder`, async function () {
this.timeout(60000);
const daCtx = { org: 'wknd', users: [{email: "[email protected]"}] };
await env.DA_CONTENT.put('wknd.props', '{"key":"value"}');
const details = { source: 'pages', destination: 'pages-newdir'};
const resp = await copyObject(env, daCtx, details);
assert.strictEqual(resp.status, 204);
const head = await env.DA_CONTENT.head('wknd/pages-newdir/index1.html');
assert(head);
});
});
});

describe('rename', () => {
Expand Down Expand Up @@ -148,45 +122,5 @@ describe('Object copy', () => {
renamed = await env.DA_CONTENT.head('wknd/newdir.props');
assert(renamed)
});

describe ('performance', () => {
const limit = 10000;
beforeEach(async function () {
this.timeout(60000);
// Prep the content.
for (let i = 0; i < limit; i += 100) {
for (let j = 0; j < 100; j++) {
const promises = [];
promises.push(env.DA_CONTENT.put(`wknd/pages/index${i+j}.html`, 'content'));
await Promise.all(promises);
}
}
});

it (`rename handles ${limit} files in folder`, async function() {
this.timeout(60000);

const daCtx = { org: 'wknd', users: [{ email: "[email protected]" }] };
await env.DA_CONTENT.put('wknd.props', '{"key":"value"}');
const details = { source: 'pages', destination: 'pages-newdir' };
const resp = await copyObject(env, daCtx, details, true);
assert.strictEqual(resp.status, 204);

let r2o = await env.DA_CONTENT.list({ prefix: 'wknd/pages/' });
assert.strictEqual(r2o.truncated, false)

let cursor;
let total = 0;
do {
r2o = await env.DA_CONTENT.list({ prefix: 'wknd/pages-newdir/', cursor });
total += r2o.objects.length;
cursor = r2o.cursor;
} while (r2o.truncated);

assert.deepStrictEqual(total, limit);
let renamed = await env.DA_CONTENT.head('wknd/pages-newdir/index1.html');
assert(renamed);
});
});
});
});

0 comments on commit aaa9a26

Please sign in to comment.