Skip to content

Commit

Permalink
fix: Reduced test data size
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-werner-casra authored and floryst committed Feb 2, 2024
1 parent ef73c33 commit 95250bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
16 changes: 8 additions & 8 deletions Sources/IO/Core/DataAccessHelper/MockDataAccessHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ function createMockIndexJSON(fileId, byteLength) {
}

const MockData = {
'test01/index.json': () => createMockIndexJSON('test01', 100 * MiB),
'test01/data/test01.gz': () => new Uint8Array(100 * MiB),
'test02/index.json': () => createMockIndexJSON('test02', 200 * MiB),
'test02/data/test02.gz': () => new Uint8Array(200 * MiB),
'test03/index.json': () => createMockIndexJSON('test03', 150 * MiB),
'test03/data/test03.gz': () => new Uint8Array(150 * MiB),
'test04/index.json': () => createMockIndexJSON('test04', 400 * MiB),
'test04/data/test04.gz': () => new Uint8Array(400 * MiB),
'test01/index.json': () => createMockIndexJSON('test01', 10 * MiB),
'test01/data/test01.gz': () => new Uint8Array(10 * MiB),
'test02/index.json': () => createMockIndexJSON('test02', 20 * MiB),
'test02/data/test02.gz': () => new Uint8Array(20 * MiB),
'test03/index.json': () => createMockIndexJSON('test03', 15 * MiB),
'test03/data/test03.gz': () => new Uint8Array(15 * MiB),
'test04/index.json': () => createMockIndexJSON('test04', 40 * MiB),
'test04/data/test04.gz': () => new Uint8Array(40 * MiB),
};

// ----------------------------------------------------------------------------
Expand Down
36 changes: 15 additions & 21 deletions Sources/IO/Core/HttpDataSetReader/test/testHttpDataSetReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import test from 'tape';
import vtkHttpDataSetReader from 'vtk.js/Sources/IO/Core/HttpDataSetReader';
import MockDataAccessHelper from 'vtk.js/Sources/IO/Core/DataAccessHelper/MockDataAccessHelper';

const maxTestDurationMS = 3000;

function runTests(testCases) {
let promise = Promise.resolve();
testCases.forEach((testCase) => {
Expand Down Expand Up @@ -39,12 +37,6 @@ function fetchArrayTest(
callTracker.fetchArray.length,
];

const timeout = setTimeout(() => {
console.log('Ran into timeout during test.');
resolve();
t.end();
}, 100);

reader.setUrl(url, { loadData: true }).then(
(v) => {
// determine the expected amount of calls of the fetch methods
Expand Down Expand Up @@ -88,10 +80,8 @@ function fetchArrayTest(
}
}
resolve(v);
clearTimeout(timeout);
},
(err) => {
clearTimeout(timeout);
reject(err);
}
);
Expand All @@ -100,13 +90,12 @@ function fetchArrayTest(

test('Caching capabilities of vtkHttpDataSetReader with unlimited cache.', async (t) => {
const reader = vtkHttpDataSetReader.newInstance({ fetchGzip: true });
const originalAccessHelper = reader.getDataAccessHelper();
reader.setDataAccessHelper(MockDataAccessHelper);
reader.clearCache();

const callTracker = MockDataAccessHelper.getCallTracker();

const timeout = setTimeout(t.end, maxTestDurationMS);

await runTests([
// set cache to unlimited size
(resolve, _) => {
Expand Down Expand Up @@ -138,23 +127,26 @@ test('Caching capabilities of vtkHttpDataSetReader with unlimited cache.', async
fetchArrayTest(t, reader, callTracker, 'http://mockData/test03', true),
]);
t.end();
clearTimeout(timeout);

reader.setDataAccessHelper(originalAccessHelper);
// clearTimeout(timeout);
});

test('Caching capabilities of vtkHttpDataSetReader with limited cache.', async (t) => {
const reader = vtkHttpDataSetReader.newInstance({ fetchGzip: true });
const originalAccessHelper = reader.getDataAccessHelper();
reader.setDataAccessHelper(MockDataAccessHelper);
reader.clearCache();

const callTracker = MockDataAccessHelper.getCallTracker();

const timeout = setTimeout(t.end, maxTestDurationMS);
// const timeout = setTimeout(t.end, maxTestDurationMS);

await runTests([
// set cache to 300 MiB -> Forces to dispose items accessed furthest in the past
// set cache to 30 MiB -> Forces to dispose items accessed furthest in the past
(resolve, _) => {
reader.setMaxCacheSize(300);
t.equals(reader.getMaxCacheSize(), 300, 'Cache was set to "300 MiB"');
reader.setMaxCacheSize(30);
t.equals(reader.getMaxCacheSize(), 30, 'Cache was set to "300 MiB"');
resolve();
},

Expand Down Expand Up @@ -191,18 +183,19 @@ test('Caching capabilities of vtkHttpDataSetReader with limited cache.', async (
fetchArrayTest(t, reader, callTracker, 'http://mockData/test04', false, []),
]);
t.end();
clearTimeout(timeout);

reader.setDataAccessHelper(originalAccessHelper);
// clearTimeout(timeout);
});

test('Disabled cache on vtkHttpDataSetReader.', async (t) => {
const reader = vtkHttpDataSetReader.newInstance({ fetchGzip: true });
const originalAccessHelper = reader.getDataAccessHelper();
reader.setDataAccessHelper(MockDataAccessHelper);
reader.clearCache();

const callTracker = MockDataAccessHelper.getCallTracker();

const timeout = setTimeout(t.end, maxTestDurationMS);

const createDisabledCacheTests = (disable) => [
// disable caching
(resolve, _) => {
Expand Down Expand Up @@ -241,5 +234,6 @@ test('Disabled cache on vtkHttpDataSetReader.', async (t) => {
...createDisabledCacheTests(undefined),
]);
t.end();
clearTimeout(timeout);

reader.setDataAccessHelper(originalAccessHelper);
});

0 comments on commit 95250bc

Please sign in to comment.