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 reinit cached browser session in worker #770

Merged
merged 1 commit into from
Jul 4, 2023

Conversation

DudaGod
Copy link
Member

@DudaGod DudaGod commented Jul 3, 2023

What is done?

Stop using cache of browsers sessions in worker. Causes:

  • selenium/selenoid/... return se:cdp capability in response with sessionId on the end of the url and we don't modify it;
  • if use cdp protocol to quickly open browsers (in the near future), then we need reinitialize additional options in cached browsers;
  • no big difference in execution speed, but a lot of problem with support in future.

@DudaGod DudaGod force-pushed the HERMIONE-1060.do_not_reinit_session branch from 1044a00 to 7d6e74e Compare July 3, 2023 17:14
@@ -52,15 +52,6 @@ module.exports = class ExistingBrowser extends Browser {
return this;
}

async reinit(sessionId, sessionOpts) {
Copy link
Member Author

@DudaGod DudaGod Jul 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Данный метод использовался для использования закешированного инстанса браузера. Чтобы его реиспользовать подменялся только sessionId.

На реиспользование закешированного инстанса уходит примерно 0.1ms, а на создание нового около 100ms. Т.е. реиспользование инстанса работает в 1000 раз быстрее, но так как значения не существенные, то какой-то значимой просадки при выполнении тестов не будет. Зато в будущем не будет гемора с поддержкой.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

при этом замена самого session id происходит не всегда

@@ -102,10 +102,6 @@ module.exports = class Browser {
return this.publicAPI.sessionId;
}

set sessionId(id) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Выгасил возможность переопределять sessionId. Данный инстанс используется только локально и наружу пользователю не торчит.

markAsBroken() {
this.applyState({ isBroken: true });

this._stubCommands();
}

quit() {
this.sessionId = null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Использовался, чтобы понять можно ли реинициализировать закешированный инстанс браузера

@@ -50,7 +31,6 @@ module.exports = class BrowserPool {
throw error;
}

browser.sessionId = sessionId;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь подменять sessionId теперь тоже не нужно.

@DudaGod DudaGod force-pushed the HERMIONE-1060.do_not_reinit_session branch from 8d80439 to 7d6e74e Compare July 4, 2023 09:22
? _.isNil(browser.sessionId) && browser.version === browserVersion
: _.isNil(browser.sessionId);
});
let browser;
Copy link
Contributor

@rprovodenko rprovodenko Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


            const browser = Browser.create(this._config, browserId, browserVersion, this._emitter);
            try {
                await browser.init({ sessionId, sessionCaps, sessionOpts }, this._calibrator);
             catch (e) {
                browser.markAsBroken();
                this.freeBrowser(browser);
                throw Object.assign(error, { meta: browser.meta });
            }

            this._emitter.emit(WorkerEvents.NEW_BROWSER, browser.publicAPI, { browserId: browser.id, browserVersion });

            return browser;

@DudaGod DudaGod force-pushed the HERMIONE-1060.do_not_reinit_session branch from 7d6e74e to 761dcb8 Compare July 4, 2023 11:28
@DudaGod DudaGod merged commit 36a63d1 into master Jul 4, 2023
@DudaGod DudaGod deleted the HERMIONE-1060.do_not_reinit_session branch July 4, 2023 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants