Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not lost "testXReqId" when using "parallelLimit" #843

Merged
merged 1 commit into from
Feb 12, 2024
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
11 changes: 6 additions & 5 deletions src/browser-pool/limited-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ module.exports = class LimitedPool extends Pool {
--this._requests;

const nextRequest = this._lookAtNextRequest();
const compositeIdForNextRequest = nextRequest && buildCompositeBrowserId(nextRequest.id, nextRequest.version);
const compositeIdForNextRequest =
nextRequest && buildCompositeBrowserId(nextRequest.id, nextRequest.opts.version);
const hasFreeSlots = this._launched < this._limit;
const shouldFreeUnusedResource = this._isSpecificBrowserLimiter && this._launched > this._requests;
const force = opts.force || shouldFreeUnusedResource;
Expand Down Expand Up @@ -83,10 +84,9 @@ module.exports = class LimitedPool extends Pool {
this.log("queuing the request");

const queue = opts.highPriority ? this._highPriorityRequestQueue : this._requestQueue;
const { version } = opts;

return new Promise((resolve, reject) => {
queue.push({ id, version, resolve, reject });
queue.push({ id, opts, resolve, reject });
});
}

Expand All @@ -111,11 +111,12 @@ module.exports = class LimitedPool extends Pool {
const queued = this._highPriorityRequestQueue.shift() || this._requestQueue.shift();

if (queued) {
const compositeId = buildCompositeBrowserId(queued.id, queued.version);
const compositeId = buildCompositeBrowserId(queued.id, queued.opts.version);

this.log(`has queued requests for ${compositeId}`);
this.log(`remaining queue length: ${this._requestQueue.length}`);
this._newBrowser(queued.id, { version: queued.version }).then(queued.resolve, queued.reject);

this._newBrowser(queued.id, queued.opts).then(queued.resolve, queued.reject);
} else {
this._launched--;
}
Expand Down
2 changes: 1 addition & 1 deletion src/runner/test-runner/regular-test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports = class RegularTestRunner extends Runner {

this._browser = await this._browserAgent.getBrowser({ state });

// use correct state for cached browsers
// TODO: move logic to caching pool (in order to use correct state for cached browsers)
if (this._browser.state.testXReqId !== state.testXReqId) {
this._browser.applyState(state);
}
Expand Down
30 changes: 25 additions & 5 deletions test/src/browser-pool/limited-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,33 @@ describe("browser-pool/limited-pool", () => {
assert.equal(bro, browser);
});

it("should pass opts to underlying pool", async () => {
const browser = stubBrowser("bro");
underlyingPool.getBrowser.returns(Promise.resolve(browser));
describe("should pass opts to underlying pool from", () => {
it("first requested browser", async () => {
const browser = stubBrowser("bro");
underlyingPool.getBrowser.returns(Promise.resolve(browser));

await makePool_().getBrowser("bro", { some: "opt" });
await makePool_().getBrowser("bro", { some: "opt" });

assert.calledOnceWith(underlyingPool.getBrowser, "bro", { some: "opt" });
assert.calledOnceWith(underlyingPool.getBrowser, "bro", { some: "opt" });
});

it("queued browser", async () => {
const browser1 = stubBrowser("bro");
const browser2 = stubBrowser("bro");
underlyingPool.getBrowser
.onFirstCall()
.returns(Promise.resolve(browser1))
.onSecondCall()
.returns(Promise.resolve(browser2));

const pool = await makePool_({ limit: 1 });
await pool.getBrowser("bro", { some: "opt1" });
// should be called without await
Promise.delay(100).then(() => pool.freeBrowser(browser1));
await pool.getBrowser("bro", { another: "opt2" });

assert.calledWith(underlyingPool.getBrowser.secondCall, "bro", { another: "opt2" });
});
});
});

Expand Down
Loading