Page MenuHomePhabricator

Reduce bot requests in Wikibase selenium tests
Open, LowPublic

Description

I noticed that Wikibase Selenium tests involve a lot of overhead with browser requests related to mwbot, and we could consolidate some of these.

For example, instead of creating a new MWBot every time createItem() is called, which in turn requires logging in and retrieving an edit token, we could create a single bot instance and store this in the class. We'd have to change the style of calling createItem() to do something like const api = new WikibaseApi(); api.createItem() rather than the existing WikibaseApi.createItem() but that doesn't seem too onerous.

We could also create a single WikibaseApi object in a beforeSuite() hook and reference that in all tests rather than creating a fresh one before each test.

Event Timeline

Similarly, there are lots of calls to Api.bot() inside individual tests, and these could be consolidated into a single bot created in the before() hook.

Change 698484 had a related patch set uploaded (by Kosta Harlan; author: Kosta Harlan):

[mediawiki/extensions/Wikibase@master] selenium: Reuse WikibaseApi, update to wdio-wikibase 5.2.0

https://gerrit.wikimedia.org/r/698484

Can we hold off on this for a bit? I’m looking into making the bot support chronology protector better in T277862, which also requires sharing the same instance; if that works, we can hopefully draw some lessons from that for wdio-wikibase.

Can we hold off on this for a bit? I’m looking into making the bot support chronology protector better in T277862, which also requires sharing the same instance; if that works, we can hopefully draw some lessons from that for wdio-wikibase.

That's OK with me, although the patches should (in theory, completely non-tested) have the sharing same instance part already done in wdio-wikibase plus the extension.

Can we hold off on this for a bit? I’m looking into making the bot support chronology protector better in T277862, which also requires sharing the same instance; if that works, we can hopefully draw some lessons from that for wdio-wikibase.

That's OK with me, although the patches should (in theory, completely non-tested) have the sharing same instance part already done in wdio-wikibase plus the extension.

Oops, I didn't push patches for the submodules. But I have those updated locally as well.

Yes, but if the chronology protector stuff works out, then I suspect it would make sense to pass an MWBot into wdio-wikibase, and it wouldn’t create its own instance at all. (WIP is at https://gerrit.wikimedia.org/r/c/mediawiki/extensions/WikibaseLexeme/+/698517 if you’re interested.)

Apparently using different MWBot instances was a deliberate change about two years ago, departing from the previous state of using the same mwbot for everything: see Wikibase change and WikibaseLexeme change. CC @Addshore and @Tarrow. (Neither change has a task attached, but the CSRF token race condition seems to be real: I got CSRF token errors in this WikibaseLexeme change where I’m trying to merge the MWBot instances again.)

(…the CSRF token race condition seems to be real: I got CSRF token errors in this WikibaseLexeme change where I’m trying to merge the MWBot instances again.)

In PS3 those errors vanished (that version logs in immediately after creating the MWBot instance – I assume previously, some requests with edit token were made before logging in, and then the wrong token continued to be used after login, because MWBot doesn’t seem to reset it automatically), so I’d welcome review on that change now. If it looks sensible, I think we should try to do something similar in wdio-wikibase as well.

Change 698484 abandoned by Kosta Harlan:

[mediawiki/extensions/Wikibase@master] [WIP] selenium: Reuse WikibaseApi, update to wdio-wikibase 5.2.0

Reason:

https://gerrit.wikimedia.org/r/698484