diff options
author | Mikolaj Boc <mikolaj.boc@qt.io> | 2023-01-04 09:54:23 +0100 |
---|---|---|
committer | Mikolaj Boc <mikolaj.boc@qt.io> | 2023-01-24 08:34:42 +0100 |
commit | 025659a18c45308c9219532fe7c2961f786d4e1a (patch) | |
tree | b8e8fe9b07bc9ef849dde7a70a9ef746fdab5af5 /util | |
parent | 897579edabfadd8309581659b578752b3c3bca0f (diff) | |
download | qtbase-025659a18c45308c9219532fe7c2961f786d4e1a.tar.gz |
wasm testrunner: Join output into batches
Sending each line in separate POST requests seems to clog emrun.
Join the output in 300ms intervals so that the number of requests is
limited to 3,(3) per second.
Fixes: QTBUG-109827
Change-Id: I099e8cc14d9d162c54b7040b62297d1070b234c3
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'util')
-rw-r--r-- | util/wasm/batchedtestrunner/emrunadapter.js | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/util/wasm/batchedtestrunner/emrunadapter.js b/util/wasm/batchedtestrunner/emrunadapter.js index cd793a38f2..96c5624131 100644 --- a/util/wasm/batchedtestrunner/emrunadapter.js +++ b/util/wasm/batchedtestrunner/emrunadapter.js @@ -5,8 +5,13 @@ import { RunnerStatus, TestStatus } from './batchedtestrunner.js'; // Sends messages to the running emrun instance via POST requests. export class EmrunCommunication { + static #BATCHING_DELAY = 300; + #indexOfMessage = 0; - #postOutputPromises = []; + #postOutputPromise; + // Accumulate output in a batch that gets sent with a delay so that the emrun http server + // does not get pounded with requests. + #nextOutputBatch = null; #post(body) { return fetch('stdio.html', { @@ -15,10 +20,11 @@ export class EmrunCommunication { }); } - // Returns a promise whose resolution signals that all outstanding traffic to the emrun instance - // has been completed. - waitUntilAllSent() { - return Promise.all(this.#postOutputPromises); + // Waits for the output sending to finish, if any output transfer is still in progress. + async waitUntilAllSent() + { + if (this.#postOutputPromise) + await this.#postOutputPromise; } // Posts the exit status to the running emrun instance. Emrun will drop connection unless it is @@ -29,13 +35,25 @@ export class EmrunCommunication { // Posts an indexed output chunk to the running emrun instance. Each consecutive call to this // method increments the output index by 1. - postOutput(output) { - const newPromise = this.#post(`^out^${this.#indexOfMessage++}^${output}`); - this.#postOutputPromises.push(newPromise); - newPromise.finally(() => { - this.#postOutputPromises.splice(this.#postOutputPromises.indexOf(newPromise), 1); - }); - return newPromise; + postOutput(output) + { + if (this.#nextOutputBatch) { + this.#nextOutputBatch += output; + } else { + this.#nextOutputBatch = output; + this.#postOutputPromise = new Promise(resolve => + { + window.setTimeout(() => + { + const toSend = this.#nextOutputBatch; + this.#nextOutputBatch = null; + this.#post(`^out^${this.#indexOfMessage++}^${toSend}$`) + .finally(resolve); + }, EmrunCommunication.#BATCHING_DELAY); + }); + } + + return this.#postOutputPromise; } } |