Page MenuHomePhabricator

MediaWiki webdriver afterTest hook should catch mwbot issues/exceptions
Closed, ResolvedPublic

Description

cd tests/selenium
 ../../node_modules/.bin/wdio

The BlankPage test passes:

[chrome #0-0] Running: chrome
[chrome #0-0]
[chrome #0-0]   BlankPage
[chrome #0-0]
[chrome #0-0]   BlankPage
[chrome #0-0]       ✓ should have its title
[chrome #0-0]
[chrome #0-0]
[chrome #0-0] 1 passing (1s)

The next ones are failing with no meaningful output

	Screenshot: /home/hashar/projects/mediawiki/core/tests/selenium/log/should-be-re-creatable.png


	Screenshot: /home/hashar/projects/mediawiki/core/tests/selenium/log/should-be-re-creatable.png

(node:30264) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): TypeError: Cannot read property 'currentRetry' of undefined

	Screenshot: /home/hashar/projects/mediawiki/core/tests/selenium/log/should-have-history.png


	Screenshot: /home/hashar/projects/mediawiki/core/tests/selenium/log/should-have-history.png

/home/hashar/projects/mediawiki/core/node_modules/webdriverio/build/lib/utils/ReporterStats.js:362
            if (!suiteStats.hooks[uid]) throw Error(`Unrecognised hook [${runner.title}] for suite [${runner.parent}]`);
                                        ^

Error: Unrecognised hook ["after each" hook for "should be deletable"] for suite [Page]
    at Error (native)
    at ReporterStats.getHookStats (/home/hashar/projects/mediawiki/core/node_modules/webdriverio/build/lib/utils/ReporterStats.js:362:47)
    at ReporterStats.hookEnd (/home/hashar/projects/mediawiki/core/node_modules/webdriverio/build/lib/utils/ReporterStats.js:332:34)
    at BaseReporter.<anonymous> (/home/hashar/projects/mediawiki/core/node_modules/webdriverio/build/lib/utils/BaseReporter.js:147:25)
    at emitOne (events.js:96:13)
    at BaseReporter.emit (events.js:188:7)
    at BaseReporter.handleEvent (/home/hashar/projects/mediawiki/core/node_modules/webdriverio/build/lib/utils/BaseReporter.js:300:27)
    at Launcher.messageHandler (/home/hashar/projects/mediawiki/core/node_modules/webdriverio/build/lib/launcher.js:688:28)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
(node:30264) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 5): Error: channel closed
`

should-be-re-creatable.png:

should-have-history.png

Event Timeline

hashar created this task.Jun 25 2018, 5:29 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJun 25 2018, 5:29 PM

In the afterTest hook I added a console.log( test ); and it shows that 'should be re-creatable` has an issue with mwbot doing a request:

Error: invalidjson: No valid JSON response
    at Context.<anonymous> (specs/page.js:39:11)
    at Promise.F (node_modules/core-js/library/modules/_export.js:36:28)
    at rawRequest.then (node_modules/mwbot/src/index.js:249:31)
    at tryCatcher (node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)

That comes from mwbot:

229     /**
230      *Executes a request with the ability to use custom parameters and custom request options
231      *
232      * @param {object} params               Request Parameters
233      * @param {object} customRequestOptions Custom request options
234      *
235      * @returns {bluebird}
236      */
237     request(params, customRequestOptions) {
238 
239         return new Promise((resolve, reject) => {
240 
241             this.globalRequestOptions.uri = this.options.apiUrl;
242 
243             let requestOptions = MWBot.merge(this.globalRequestOptions, customRequestOptions);
244             requestOptions.form = MWBot.merge(requestOptions.form, params);
245 
246             this.rawRequest(requestOptions).then((response) => {
247 
248                 if (typeof response !== 'object') {
249                     let err = new Error('invalidjson: No valid JSON response');
250                     err.code = 'invalidjson';
251                     err.info = 'No valid JSON response';
252                     err.response = response;
253                     return reject(err) ;
254                 }

I was using a MW_SCRIPT env variable instead of MW_SCRIPT_PATH='/'. Hence I had post to /w/api.php instead of /api.php. Solved!

Keeping this task around, I would like the afterTest hook to catch the issue and dump the stack / url. That could help in the future.

zeljkofilipin triaged this task as Low priority.Jun 27 2018, 8:32 AM
zeljkofilipin moved this task from Inbox to Selenium on the MediaWiki-Core-Testing board.

I was using a MW_SCRIPT env variable instead of MW_SCRIPT_PATH='/'. Hence I had post to /w/api.php instead of /api.php. Solved!
Keeping this task around, I would like the afterTest hook to catch the issue and dump the stack / url. That could help in the future.

Please rename the task then. 😅

hashar renamed this task from MediaWiki webdriver.io fails mysteriously to MediaWiki webdriver afterTest hook should catch mwbot issues/exceptions.Jun 27 2018, 9:50 AM
Vvjjkkii renamed this task from MediaWiki webdriver afterTest hook should catch mwbot issues/exceptions to ubaaaaaaaa.Jul 1 2018, 1:01 AM
Vvjjkkii raised the priority of this task from Low to High.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed a subscriber: Aklapper.
JJMC89 renamed this task from ubaaaaaaaa to MediaWiki webdriver afterTest hook should catch mwbot issues/exceptions.Jul 1 2018, 3:54 AM
JJMC89 updated the task description. (Show Details)
JJMC89 added a subscriber: Aklapper.
CommunityTechBot lowered the priority of this task from High to Low.Jul 5 2018, 7:07 PM
Krinkle closed this task as Resolved.Feb 7 2019, 1:45 AM
Krinkle claimed this task.
Krinkle added a subscriber: Krinkle.

As part of the refactoring I did when creating the wdio-mediawiki package, I also made sure any exceptions and promise rejections from mwbot were caught (https://github.com/wikimedia/mediawiki/tree/42451e64/tests/selenium/wdio-mediawiki).

The problem was that some of the async function calls were not being awaited. This is an easy mistake to make due to how wdio makes some (but not all) asynchronous functions appear semi-synchronous (by using node-fibers).

mobrovac reopened this task as Open.Feb 13 2019, 12:42 AM
mobrovac added a subscriber: mobrovac.

It seems these problems are coming back around. For EventBus Gerrit 490141 we are seeing unrelated failures for jenkins tests which fit this ticket: https://integration.wikimedia.org/ci/job/quibble-vendor-mysql-hhvm-docker/34851/console and https://integration.wikimedia.org/ci/job/quibble-vendor-mysql-hhvm-docker/34856/console . Is this known?

@mobrovac This ticket is not about that error, it is about whether Jenkins will show the underlying exception message and trace from node-mwbot.

Originally (task description) it would report "Error: Unrecognised hook" with no way to determine what went wrong.

Now in latest master, if something goes wrong, the mwbot exception is shown. An example of that was cited by Antoine in T198125#4313031. I think this error itself should be filed a new task (it happens to be the same one we saw last year here, but this task isn't about that, though.)

mobrovac closed this task as Resolved.Feb 13 2019, 8:27 PM

Oh, ok, just wanted to make sure. Will file a new task. Thanks @Krinkle !

For the weird Error: Unrecognised hook ["after each" hook for "should be deletable"] for suite [Page], in this case that was caused by MWBot and got fixed by b0102bcc98c35184f5c3d6f1260a4837f2dab7e2

I filled T216818 to fix for other potential sources of exceptions.