-
Notifications
You must be signed in to change notification settings - Fork 63
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
feat: generate "X-Request-ID" header for each browser request #819
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
"use strict"; | ||
|
||
const crypto = require("crypto"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Для генерации |
||
const _ = require("lodash"); | ||
const { SAVE_HISTORY_MODE } = require("../constants/config"); | ||
const { X_REQUEST_ID_DELIMITER } = require("../constants/browser"); | ||
const history = require("./history"); | ||
const addRunStepCommand = require("./commands/runStep"); | ||
|
||
|
@@ -19,13 +21,14 @@ const CUSTOM_SESSION_OPTS = [ | |
]; | ||
|
||
module.exports = class Browser { | ||
static create(config, id, version) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Изменил api, чтобы не докидывать |
||
return new this(config, id, version); | ||
static create(config, opts) { | ||
return new this(config, opts); | ||
} | ||
|
||
constructor(config, id, version) { | ||
this.id = id; | ||
this.version = version; | ||
constructor(config, opts) { | ||
this.id = opts.id; | ||
this.version = opts.version; | ||
this.testXReqId = opts.testXReqId; | ||
|
||
this._config = config.forBrowser(this.id); | ||
this._debug = config.system.debug; | ||
|
@@ -82,7 +85,21 @@ module.exports = class Browser { | |
|
||
_getSessionOptsFromConfig(optNames = CUSTOM_SESSION_OPTS) { | ||
return optNames.reduce((options, optName) => { | ||
if (!_.isNull(this._config[optName])) { | ||
if (optName === "transformRequest") { | ||
options[optName] = req => { | ||
if (!_.isNull(this._config[optName])) { | ||
req = this._config[optName](req); | ||
} | ||
|
||
if (!req.headers["X-Request-ID"]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Юзер мог самостоятельно указать в конфиге хедер |
||
req.headers["X-Request-ID"] = `${ | ||
this.testXReqId | ||
}${X_REQUEST_ID_DELIMITER}${crypto.randomUUID()}`; | ||
} | ||
|
||
return req; | ||
}; | ||
} else if (!_.isNull(this._config[optName])) { | ||
options[optName] = this._config[optName]; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const MIN_CHROME_VERSION_SUPPORT_ISOLATION = 93; | ||
export const X_REQUEST_ID_DELIMITER = "__"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ module.exports = class HighPriorityBrowserAgent { | |
this._browserAgent = browserAgent; | ||
} | ||
|
||
getBrowser() { | ||
return this._browserAgent.getBrowser({ highPriority: true }); | ||
getBrowser(opts = {}) { | ||
return this._browserAgent.getBrowser({ ...opts, highPriority: true }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Нашел баг, что при ретрае теста в мету не прокидывался |
||
} | ||
|
||
freeBrowser(...args) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
"use strict"; | ||
|
||
const crypto = require("crypto"); | ||
const _ = require("lodash"); | ||
const { Runner } = require("../runner"); | ||
const logger = require("../../utils/logger"); | ||
|
@@ -64,6 +65,7 @@ module.exports = class RegularTestRunner extends Runner { | |
sessionCaps: this._browser.capabilities, | ||
sessionOpts: this._browser.publicAPI.options, | ||
file: this._test.file, | ||
testXReqId: this._browser.testXReqId, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Прокидываю x-req-id теста в worker, чтобы затем добросить его до браузера в воркере ( |
||
}); | ||
} | ||
|
||
|
@@ -80,7 +82,7 @@ module.exports = class RegularTestRunner extends Runner { | |
|
||
async _getBrowser() { | ||
try { | ||
this._browser = await this._browserAgent.getBrowser(); | ||
this._browser = await this._browserAgent.getBrowser({ testXReqId: crypto.randomUUID() }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вот тут генерится x-req-id для теста и прокидывается в браузер (запущенный в мастере, т.е. в |
||
this._test.sessionId = this._browser.sessionId; | ||
|
||
return this._browser; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Изменил api, чтобы не докидывать
testXReqId
отдельным параметром. Похожий подход присутствует и в других файлах, поэтому их отдельно комментировать не буду.