Skip to content

Commit 4629828

Browse files
committed
cleanup
1 parent 6f59500 commit 4629828

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

JetStreamDriver.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ const fileLoader = (function() {
239239
class Driver {
240240
constructor() {
241241
this.isReady = false;
242+
this.isDone = false;
243+
this.incrementalResults = [];
242244
this.benchmarks = [];
243245
this.blobDataCache = { };
244246
this.loadCache = { };
@@ -282,15 +284,13 @@ class Driver {
282284
console.log(benchmark.name)
283285

284286
if (isInBrowser) {
285-
globalThis.dispatchEvent(new CustomEvent("JetStreamBenchmarkDone", {
286-
detail: {
287-
name: benchmark.name,
288-
results: {
289-
score: benchmark.score,
290-
...benchmark.subScores(),
291-
}
287+
this.incrementalResults.push({
288+
name: benchmark.name,
289+
results: {
290+
Score: benchmark.score,
291+
...benchmark.subScores(),
292292
}
293-
}));
293+
});
294294
const cache = JetStream.blobDataCache;
295295
for (const file of benchmark.plan.files) {
296296
const blobData = cache[file];
@@ -344,13 +344,20 @@ class Driver {
344344

345345
this.reportScoreToRunBenchmarkRunner();
346346
this.dumpJSONResultsIfNeeded();
347+
this.isDone = true;
347348
if (isInBrowser) {
348349
globalThis.dispatchEvent(new CustomEvent("JetStreamDone", {
349350
detail: this.resultsObject()
350351
}));
351352
}
352353
}
353354

355+
drainIncrementalResults() {
356+
const currentIncrementalResults = this.incrementalResults;
357+
this.incrementalResults = [];
358+
return currentIncrementalResults
359+
}
360+
354361
runCode(string)
355362
{
356363
if (!isInBrowser) {

tests/run.mjs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ async function testEnd2End() {
8080
const driver = await new Builder().withCapabilities(capabilities).build();
8181
let results;
8282
try {
83-
console.log("Preparing JetStream");
84-
await driver.get(`http://localhost:${PORT}/index.html?worstCaseCount=2&iterationCount=3`);
83+
const url = `http://localhost:${PORT}/index.html?worstCaseCount=2&iterationCount=3`;
84+
console.log(`JetStream PREPARE ${url}`);
85+
await driver.get(url);
8586
await driver.executeAsyncScript((callback) => {
8687
globalThis.addEventListener("JetStreamReady", () => callback());
8788
// We might not get a chance to install the on-ready listener, thus
@@ -99,34 +100,27 @@ async function testEnd2End() {
99100
}
100101

101102
async function benchmarkResults(driver) {
102-
console.log("Starting JetStream");
103+
console.log("JetStream START");
103104
await driver.manage().setTimeouts({ script: 60_000 });
104-
await driver.executeScript(() => {
105-
globalThis.JetStreamDone = false;
106-
globalThis.JetStreamResults = [];
107-
globalThis.addEventListener("JetStreamDone", event => {
108-
globalThis.JetStreamDone = true;
109-
});
110-
globalThis.addEventListener("JetStreamBenchmarkDone", event => {
111-
globalThis.JetStreamResults.push(event.detail);
112-
});
113-
JetStream.start();
105+
await driver.executeAsyncScript((callback) => {
106+
globalThis.JetStream.start();
107+
callback();
114108
});
115109
await new Promise(resolve => pollIncrementalResults(driver, resolve));
116110
const resultString = await driver.executeScript(() => {
117-
return JSON.stringify(JetStream.resultsObject());
111+
return JSON.stringify(globalThis.JetStream.resultsObject());
118112
});
119113
return JSON.parse(resultString);
120114
}
121115

122116
const UPDATE_INTERVAL = 250;
123117
async function pollIncrementalResults(driver, resolve) {
124118
const intervalId = setInterval(async function logResult() {
125-
const {done, results} = await driver.executeAsyncScript((callback) => {
126-
callback({
127-
done: globalThis.JetStreamDone,
128-
results: JSON.stringify(globalThis.JetStreamResults.splice(0, Infinity)),
129-
});
119+
const {done, results} = await driver.executeScript(() => {
120+
return {
121+
done: globalThis.JetStream.isDone,
122+
results: JSON.stringify(globalThis.JetStream.drainIncrementalResults()),
123+
};
130124
});
131125
JSON.parse(results).forEach(logIncrementalResult);
132126
if (done) {

0 commit comments

Comments
 (0)