Skip to content

Commit 553d3f7

Browse files
authored
Add validate method for async-fs and sync-fs (#111)
Make sure we have global side-effects and validation of the final result. Drive-by-fix: - Convert testList items to lowerCase for better ergonomics - Print error stack if we see remote failures in the end2end tests
1 parent fe1f348 commit 553d3f7

File tree

4 files changed

+51
-8
lines changed

4 files changed

+51
-8
lines changed

JetStreamDriver.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,9 +2394,10 @@ function processTestList(testList)
23942394
else
23952395
benchmarkNames = testList.split(/[\s,]/);
23962396

2397-
for (const name of benchmarkNames) {
2397+
for (let name of benchmarkNames) {
2398+
name = name.toLowerCase();
23982399
if (benchmarksByTag.has(name))
2399-
benchmarks.push(...findBenchmarksByTag(name));
2400+
benchmarks.concat(findBenchmarksByTag(name));
24002401
else
24012402
benchmarks.push(findBenchmarkByName(name));
24022403
}

generators/async-file-system.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ class File {
5656
set data(dataView) { this._data = dataView; }
5757

5858
swapByteOrder() {
59+
let hash = 0x1a2b3c4d;
5960
for (let i = 0; i < Math.floor(this.data.byteLength / 8) * 8; i += 8) {
60-
this.data.setFloat64(i, this.data.getFloat64(i, isLittleEndian), !isLittleEndian);
61+
const data = this.data.getFloat64(i, isLittleEndian);
62+
this.data.setFloat64(i, data, !isLittleEndian);
63+
hash ^= data | 0;
6164
}
65+
return hash;
6266
}
6367
}
6468

@@ -171,11 +175,16 @@ async function setupDirectory() {
171175
}
172176

173177
class Benchmark {
178+
EXPECTED_FILE_COUNT = 666;
179+
180+
totalFileCount = 0;
181+
lastFileHash = undefined;
182+
174183
async runIteration() {
175184
const fs = await setupDirectory();
176185

177186
for await (let { entry: file } of fs.forEachFileRecursively()) {
178-
file.swapByteOrder();
187+
this.lastFileHash = file.swapByteOrder();
179188
}
180189

181190
for await (let { name, entry: dir } of fs.forEachDirectoryRecursively()) {
@@ -187,5 +196,17 @@ class Benchmark {
187196
}
188197
}
189198
}
199+
200+
for await (let _ of fs.forEachFileRecursively()) {
201+
this.totalFileCount++;
202+
}
203+
}
204+
205+
validate(iterations) {
206+
const expectedFileCount = this.EXPECTED_FILE_COUNT * iterations;
207+
if (this.totalFileCount != expectedFileCount)
208+
throw new Error(`Invalid total file count ${this.totalFileCount}, expected ${expectedFileCount}.`);
209+
if (this.lastFileHash === undefined)
210+
throw new Error(`Invalid file hash: ${this.lastFileHash}`);
190211
}
191212
}

generators/sync-file-system.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,13 @@ class File {
5353
set data(dataView) { this._data = dataView; }
5454

5555
swapByteOrder() {
56+
let hash = 0x1a2b3c4d;
5657
for (let i = 0; i < Math.floor(this.data.byteLength / 8) * 8; i += 8) {
57-
this.data.setFloat64(i, this.data.getFloat64(i, isLittleEndian), !isLittleEndian);
58+
const data = this.data.getFloat64(i, isLittleEndian);
59+
this.data.setFloat64(i, data, !isLittleEndian);
60+
hash ^= data | 0;
5861
}
62+
return hash;
5963
}
6064
}
6165

@@ -161,11 +165,16 @@ function setupDirectory() {
161165
}
162166

163167
class Benchmark {
168+
EXPECTED_FILE_COUNT = 411;
169+
170+
totalFileCount = 0;
171+
lastFileHash = undefined;
172+
164173
runIteration() {
165174
const fs = setupDirectory();
166175

167176
for (let { entry: file } of fs.forEachFileRecursively()) {
168-
file.swapByteOrder();
177+
this.lastFileHash = file.swapByteOrder();
169178
}
170179

171180
for (let { name, entry: dir } of fs.forEachDirectoryRecursively()) {
@@ -178,5 +187,17 @@ class Benchmark {
178187
}
179188
}
180189
}
190+
191+
for (let _ of fs.forEachFileRecursively()) {
192+
this.totalFileCount++;
193+
}
194+
}
195+
196+
validate(iterations) {
197+
const expectedFileCount = this.EXPECTED_FILE_COUNT * iterations;
198+
if (this.totalFileCount != expectedFileCount)
199+
throw new Error(`Invalid total file count ${this.totalFileCount}, expected ${expectedFileCount}.`);
200+
if (this.lastFileHash === undefined)
201+
throw new Error(`Invalid file hash: ${this.lastFileHash}`);
181202
}
182203
}

tests/run.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async function testEnd2End(params) {
103103

104104
async function benchmarkResults(driver) {
105105
logInfo("JetStream START");
106-
await driver.manage().setTimeouts({ script: 60_000 });
106+
await driver.manage().setTimeouts({ script: 2 * 60_000 });
107107
await driver.executeAsyncScript((callback) => {
108108
globalThis.JetStream.start();
109109
callback();
@@ -118,7 +118,7 @@ async function benchmarkResults(driver) {
118118

119119
class JetStreamTestError extends Error {
120120
constructor(errors) {
121-
super(`Tests failed: ${errors.map(e => e.name).join(", ")}`);
121+
super(`Tests failed: ${errors.map(e => e.stack).join(", ")}`);
122122
this.errors = errors;
123123
}
124124

0 commit comments

Comments
 (0)