Skip to content

Commit a3448ce

Browse files
committed
fix: do not lost "testXReqId" when using "parallelLimit"
1 parent 041a3dc commit a3448ce

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

src/browser-pool/limited-pool.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ module.exports = class LimitedPool extends Pool {
4949
--this._requests;
5050

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

8586
const queue = opts.highPriority ? this._highPriorityRequestQueue : this._requestQueue;
86-
const { version } = opts;
8787

8888
return new Promise((resolve, reject) => {
89-
queue.push({ id, version, resolve, reject });
89+
queue.push({ id, opts, resolve, reject });
9090
});
9191
}
9292

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

113113
if (queued) {
114-
const compositeId = buildCompositeBrowserId(queued.id, queued.version);
114+
const compositeId = buildCompositeBrowserId(queued.id, queued.opts.version);
115115

116116
this.log(`has queued requests for ${compositeId}`);
117117
this.log(`remaining queue length: ${this._requestQueue.length}`);
118-
this._newBrowser(queued.id, { version: queued.version }).then(queued.resolve, queued.reject);
118+
119+
this._newBrowser(queued.id, queued.opts).then(queued.resolve, queued.reject);
119120
} else {
120121
this._launched--;
121122
}

src/runner/test-runner/regular-test-runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ module.exports = class RegularTestRunner extends Runner {
8686

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

89-
// use correct state for cached browsers
89+
// TODO: move logic to caching pool (in order to use correct state for cached browsers)
9090
if (this._browser.state.testXReqId !== state.testXReqId) {
9191
this._browser.applyState(state);
9292
}

test/src/browser-pool/limited-pool.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,33 @@ describe("browser-pool/limited-pool", () => {
3232
assert.equal(bro, browser);
3333
});
3434

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

39-
await makePool_().getBrowser("bro", { some: "opt" });
40+
await makePool_().getBrowser("bro", { some: "opt" });
4041

41-
assert.calledOnceWith(underlyingPool.getBrowser, "bro", { some: "opt" });
42+
assert.calledOnceWith(underlyingPool.getBrowser, "bro", { some: "opt" });
43+
});
44+
45+
it("queued browser", async () => {
46+
const browser1 = stubBrowser("bro");
47+
const browser2 = stubBrowser("bro");
48+
underlyingPool.getBrowser
49+
.onFirstCall()
50+
.returns(Promise.resolve(browser1))
51+
.onSecondCall()
52+
.returns(Promise.resolve(browser2));
53+
54+
const pool = await makePool_({ limit: 1 });
55+
await pool.getBrowser("bro", { some: "opt1" });
56+
// should be called without await
57+
Promise.delay(100).then(() => pool.freeBrowser(browser1));
58+
await pool.getBrowser("bro", { another: "opt2" });
59+
60+
assert.calledWith(underlyingPool.getBrowser.secondCall, "bro", { another: "opt2" });
61+
});
4262
});
4363
});
4464

0 commit comments

Comments
 (0)