Skip to content

Commit

Permalink
Memory test should leverage bundler (#1215)
Browse files Browse the repository at this point in the history
  • Loading branch information
thekevinscott authored Oct 13, 2023
1 parent 628cc2b commit c39b5b4
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 166 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ jobs:
- name: 'Integration Tests'
run: pnpm test:model -- --platform node --ci --verbose --skip-bundle

memory-leaks:
name: 'Memory Leaks'
integration-memory-leaks:
name: 'Integration / Memory Leaks'
runs-on: ubuntu-latest
steps:
- name: 'Checkout repository'
Expand All @@ -286,11 +286,8 @@ jobs:
with:
node-version: 16

- name: 'Bundle'
run: pnpm test:memory-leaks -- --ci --verbose --skip-test

- name: 'Memory Leak Tests'
run: pnpm test:memory-leaks -- --ci --verbose --skip-bundle
run: pnpm test:integration:memory-leaks -- --ci --verbose

build-docs:
name: 'Build Documentation'
Expand Down
24 changes: 18 additions & 6 deletions internals/http-server/src/HttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const closeHttpServer = (server: HTTPServer) => new Promise<void>((resolve, reje
resolve();
}
});
})
});


export class HttpServer {
name?: string;
Expand All @@ -55,10 +56,17 @@ export class HttpServer {
if (!await exists(this.dist)) {
throw new Error(`dist Directory "${this.dist}" supplied to server does not exist`);
}
const httpServer = createServer((request, response) => handler(request, response, {
public: this.dist,
headers: serverHeaders,
}));

const httpServer = createServer((request, response) => {
response.setHeader('Access-Control-Allow-Origin', '*');
response.setHeader('Access-Control-Request-Method', '*');
response.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
response.setHeader('Access-Control-Allow-Headers', '*');
return handler(request, response, {
public: this.dist,
headers: serverHeaders,
});
});
this.httpServer = httpServer;

await startHttpServer(httpServer, this.port);
Expand All @@ -68,7 +76,11 @@ export class HttpServer {
verbose('Starting server with tunnel');
await this.tunnel.start();
}
return this.url;
const url = this.url;
if (!url) {
throw new Error('No URL was created');
}
return url;
}

get url() {
Expand Down
2 changes: 1 addition & 1 deletion internals/test-runner/src/ClientsideTestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ export class ClientsideTestRunner {
});

// Note: these must be done sequentially; there's a race condition bug in tunnelmole
await this.server.start();
await this.fixturesServer.start();
await this.server.start();
}

async stopServers(): Promise<void> {
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"test:integration:browser": "wireit",
"test:integration:serverside": "wireit",
"test:model": "wireit",
"test:memory-leaks": "wireit",
"test:integration:memory-leaks": "wireit",
"test:unit:browser:playwright": "wireit",
"test:unit:browser:jest": "wireit",
"test:unit:node": "wireit"
Expand All @@ -54,12 +54,12 @@
"@babel/plugin-transform-modules-commonjs": "7.22.5",
"@babel/preset-env": "7.22.10",
"@babel/preset-typescript": "7.22.5",
"@internals/bundlers": "workspace:*",
"@internals/common": "workspace:*",
"@internals/upscaler-cli": "workspace:*",
"@internals/webdriver": "workspace:*",
"@internals/http-server": "workspace:*",
"@internals/test-runner": "workspace:*",
"@internals/bundlers": "workspace:*",
"@internals/upscaler-cli": "workspace:*",
"@internals/webdriver": "workspace:*",
"@rollup/plugin-commonjs": "25.0.4",
"@rollup/plugin-node-resolve": "15.2.0",
"@schemastore/package": "0.0.10",
Expand Down Expand Up @@ -313,14 +313,15 @@
"build:models"
]
},
"test:memory-leaks": {
"command": "pnpm --filter @upscalerjs/scripts test:memory-leaks",
"test:integration:memory-leaks": {
"command": "pnpm --filter @upscalerjs/scripts test:integration:memory-leaks",
"dependencies": [
"./internals/common:build",
"./internals/http-server:build",
"./internals/test-runner:build",
"./packages/upscalerjs:build:browser",
"build:models:esm"
"build:models:esm",
"bundle:esbuild"
]
},
"test:unit:browser:playwright": {
Expand Down
5 changes: 3 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"test:integration:browserstack": "pnpm __run_command ./test.ts --kind integration --platform browser --runner browserstack",
"test:integration:browser": "pnpm __run_command ./test.ts --kind integration --platform browser",
"test:integration:serverside": "pnpm __run_command ./test.ts --kind integration --platform node",
"test:memory-leaks": "pnpm __run_command ./test.ts --kind memory --platform browser",
"test:integration:memory-leaks": "pnpm __run_command ./test.ts --kind memory --platform browser",
"test:model": "pnpm __run_command ./test.ts --kind model",
"update:version": "pnpm __run_command ./package-scripts/update-version.ts",
"update:tfjs": "pnpm __run_command ./package-scripts/update-tfjs.ts",
Expand Down
7 changes: 5 additions & 2 deletions scripts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const getFolder = (platform: Platform, runner: Runner, kind: Kind) => {

const getAllTestFiles = (platform: Platform, runner: Runner, kind: Kind): string[] => {
if (kind === 'memory') {
return ['test.browser.ts'];
return ['test.browser.mts'];
}
if (kind === 'model') {
return ['model.ts'];
Expand Down Expand Up @@ -129,7 +129,7 @@ const test = async (platform: Platform | Platform[], runner: Runner, kind: Kind,
useGPU?: boolean,
watch?: boolean;
}) => {
if (skipBundle !== true && runner !== 'browserstack') {
if (skipBundle !== true && runner !== 'browserstack' && kind !== 'memory') {
const dependencies = await getDependencies(platform, runner, kind, ...positionalArgs);
const durations: number[] = [];
for (const dependency of dependencies) {
Expand All @@ -154,6 +154,9 @@ const test = async (platform: Platform | Platform[], runner: Runner, kind: Kind,
if (runner === 'browserstack') {
return ['pnpm', 'vitest', '-c', path.resolve(ROOT_DIR, './test/integration/browserstack/vite.config.mts')];
}
if (kind === 'memory') {
return ['pnpm', 'vitest', '-c', path.resolve(ROOT_DIR, './test/integration/memory/vite.config.mts')];
}
if (kind === 'integration' && platform === 'node') {
return ['pnpm', 'vitest', '-c', path.resolve(ROOT_DIR, './test/integration/serverside/vite.config.mts')];
}
Expand Down
9 changes: 0 additions & 9 deletions test/integration/browserstack.dependencies.ts

This file was deleted.

9 changes: 0 additions & 9 deletions test/integration/browserstack/tests/browser.mts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ describe('Browser Integration Tests', () => {

beforeAll(async function browserBeforeAll() {
await testRunner.beforeAll();
console.log('server url', await testRunner.getServerURL());
console.log('fixture url', await testRunner.getFixturesServerURL());
}, 20000);

afterAll(async function browserAfterAll() {
Expand All @@ -73,26 +71,19 @@ describe('Browser Integration Tests', () => {
});

test.each(browserOptions)("%j", async (capabilities: BrowserOption) => {
console.log(capabilities)
driver = getDriver({ ...capabilities, build }, { verbose: VERBOSE });
console.log('got driver')
const ROOT_URL = await testRunner.getServerURL();;
await driver.get(ROOT_URL);
console.log('got root url')
await driver.wait(async () => {
const title = await driver.getTitle();
return title.endsWith('| Loaded');
}, 3000);
console.log('got loaded page')

const fixturePath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/test/__fixtures__/fixture.png`;
const modelPath = `${await testRunner.getFixturesServerURL()}/pixel-upsampler/models/x4/x4.json`;
console.log('got fixture and model paths')
const result = await executeAsyncScript(driver, ({ fixturePath, modelPath }) => {
const Upscaler = window['Upscaler'] as any;
console.log('got upscaler')
const model = window["@upscalerjs/pixel-upsampler/x4"];
console.log("got model")
if (!model) {
throw new Error('No model found for pixel upsampler');
}
Expand Down
9 changes: 0 additions & 9 deletions test/integration/memory.dependencies.ts

This file was deleted.

Loading

0 comments on commit c39b5b4

Please sign in to comment.