Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

test: fix test context create and release #114

Merged
merged 3 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion test/test-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ for (const group of ONNX_JS_TEST_CONFIG.model) {
});

after('release session', () => {
context.release();
if (context) {
context.release();
}
});

for (const testCase of test.cases) {
Expand Down
36 changes: 24 additions & 12 deletions test/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,33 @@ export class ModelTestContext {
* create a ModelTestContext object that used in every test cases in the given ModelTest.
*/
static async create(modelTest: Test.ModelTest, profile: boolean): Promise<ModelTestContext> {
const initStart = now();
const session = await initializeSession(modelTest.modelUrl, modelTest.backend!, profile);
const initEnd = now();

for (const testCase of modelTest.cases) {
await loadTensors(testCase);
if (this.initializing) {
throw new Error(`cannot create a ModelTestContext object when the previous creation is not done`);
}

return new ModelTestContext(
session,
modelTest.backend!,
{init: initEnd - initStart, firstRun: -1, runs: [], count: 0},
profile,
);
try {
this.initializing = true;

const initStart = now();
const session = await initializeSession(modelTest.modelUrl, modelTest.backend!, profile);
const initEnd = now();

for (const testCase of modelTest.cases) {
await loadTensors(testCase);
}

return new ModelTestContext(
session,
modelTest.backend!,
{init: initEnd - initStart, firstRun: -1, runs: [], count: 0},
profile,
);
} finally {
this.initializing = false;
}
}

private static initializing = false;
}

export declare namespace ModelTestContext {
Expand Down