Page MenuHomePhabricator

MediaWiki core QUnit test (mw.now) is failing in PageTriage CI
Closed, ResolvedPublic

Description

I got the following error multiple times, https://gerrit.wikimedia.org/r/c/mediawiki/extensions/PageTriage/+/755802. I am not sure if it is PageTriage specific or not.

22:06:39 FAILED TESTS:
22:06:39   mediawiki
22:06:39     ✖ mw.now
22:06:39       Chrome Headless 90.0.4430.212 (Linux x86_64)
22:06:39     Match size of current timestamp
22:06:39     Expected: 62
22:06:39     Actual: 13
22:06:39         at Object.<anonymous> (http://localhost:9876/load.php?modules=ext.centralauth.ForeignApi%7Cext.eventLogging%7Cext.eventLogging.debug%7Cext.pageTriage.external%2Cinit%2CtoolbarStartup%7Cjquery.client%2Ccolor%2Ccookie%2ChighlightText%2ClengthLimit%2CmakeCollapsible%2Ctablesorter%2CtextSelection%7Cjquery.makeCollapsible.styles%7Cjquery.tablesorter.styles%7Cmediawiki.ForeignApi%2CString%2CTitle%2CUri%2Capi%2Ccldr%2Ccookie%2Cexperiments%2Cinspect%2CjqueryMsg%2Clanguage%2CmessagePoster%2Cqunit-testrunner%2Cstorage%2Ctemplate%2Ctoc%2Cuser%2Cutil%2Cviewport%2CvisibleTimeout%2Cwidgets%7Cmediawiki.ForeignApi.core%7Cmediawiki.language.months%2Ctestdata%7Cmediawiki.libs.pluralruleparser%7Cmediawiki.page.ready%7Cmediawiki.rcfilters.filters.ui%7Cmediawiki.special.recentchanges%7Cmediawiki.template.mustache%7Cmediawiki.widgets.MediaSearch%2CTable%2Cstyles%7Coojs%2Coojs-ui-core%2Coojs-ui-widgets%2Csinonjs%7Coojs-ui-core.icons%2Cstyles%7Coojs-ui-widgets.icons%7Coojs-ui-windows.icons%7Coojs-ui.styles.icons-content%2Cicons-editing-core%2Cicons-editing-styling%2Cicons-interactions%2Cicons-layout%2Cicons-media%2Cicons-moderation%2Cindicators%7Ctest.CentralAuth%2CEcho%2CEventLogging%2CMediaWiki%2CPageTriage&version=1p5y5:1005:238)
22:06:39         at runTest (node_modules/qunit/qunit/qunit.js:2272:35)
22:06:39         at Test.run (node_modules/qunit/qunit/qunit.js:2255:9)
22:06:39         at node_modules/qunit/qunit/qunit.js:2492:16
22:06:39         at processTaskQueue (node_modules/qunit/qunit/qunit.js:1863:26)
22:06:39         at node_modules/qunit/qunit/qunit.js:1867:13

Event Timeline

Tgr subscribed.

Are you sure it's flaky? It seems to be failing deterministically, and the timestamp length is not an assertion I would expect to have much randomness.

Are you sure it's flaky?

no, at first I just thought that I have seen this error as a flaky one before.

Lucas_Werkmeister_WMDE renamed this task from Flaky browser test in PageTriage CI to MediaWiki core QUnit test (mw.now) is flaky in PageTriage CI.Jan 21 2022, 11:28 AM
Lucas_Werkmeister_WMDE renamed this task from MediaWiki core QUnit test (mw.now) is flaky in PageTriage CI to MediaWiki core QUnit test (mw.now) is failing in PageTriage CI.Jan 21 2022, 11:31 AM

It’s a MediaWiki core test, but it seems to work on its own (including on my local wiki, where I don’t have PageTriage installed yet). Strange.

I think I found a suspect: https://github.com/wikimedia/mediawiki-extensions-Echo/blob/ceda28121fc9cc4e5ee40e26c6d649e88264ce70/tests/qunit/model/test_mw.echo.dm.NotificationItem.js#L31-L35

test_mw.echo.dm.NotificationItem.js
	QUnit.module( 'ext.echo.dm - mw.echo.dm.NotificationItem', QUnit.newMwEnvironment( {
		setup: function () {
			this.sandbox.useFakeTimers( now );
		}
	} ) );

Echo’s CI uses fake timers at some point, but does not (as far as I can tell) reset them; PageTriage pulls in Echo (zuul/parameter_functions.py, dependencies).

Change 755961 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Echo@master] Reset test fake timers on teardown

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

Change 755962 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/PageTriage@master] DNM: Test CI

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

Change 755962 abandoned by Lucas Werkmeister (WMDE):

[mediawiki/extensions/PageTriage@master] DNM: Test CI

Reason:

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

Change 755961 abandoned by Lucas Werkmeister (WMDE):

[mediawiki/extensions/Echo@master] Reset test fake timers on teardown

Reason:

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

Change 755964 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/core@master] DNM: Add more details to mw.now test

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

Change 755965 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/PageTriage@master] DNM: Test CI

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

Ok, https://integration.wikimedia.org/ci/job/quibble-vendor-mysql-php72-noselenium-docker/130793/console gives us more details:

Match size of current timestamp (1642766492252.74, rounded to 1642766492253, should look like Fri Jan 21 2022 12:01:32 GMT+0000 (Coordinated Universal Time))

Date.now() (MDN) is somehow returning a human-readable date string rather than a number of seconds. I’m guessing some test must be overriding it, though I haven’t found the culprit with codesearch yet.

Wait, lol, this is actually in PageTriage itself?!

https://gerrit.wikimedia.org/g/mediawiki/extensions/PageTriage/+/c9892e8830afd18d6d320a786c88c7f63a049289/modules/external/date.js#41

Date.now=function(){return new Date();};

I assume that’s accidentally missing a + sign, all the polyfills I’ve seen in codesearch were like return +new Date(). Returning new Date() without any type coercion isn’t ideal.

On closer observation, no, it’s not accidentally missing anything, the rest of this external/date.js library actually expects Date.now() to return an object, calling methods like .clearTime() and .add(c) on it. I guess this library (copyright 2006-7) just predates any standardized Date.now(), and decided to add its own custom method to Date.now(), which now conflicts with the standard method that the MediaWiki core test relies on.

I have no idea why this only started failing recently-ish, CI was apparently still green in October.

Suggestions to unblock https://gerrit.wikimedia.org/r/c/mediawiki/extensions/PageTriage/+/755802 (which will resolve two wmf.19 train blockers, so it’s kind of important):

  • force-merge
  • make the MediaWiki core test use +new Date() instead of Date.now() (could be reverted after the PageTriage change successfully merges)
  • get rid of date.js

I don’t think the third option is realistic in time for wmf.19, though it’s certainly the best solution in the long run; any preferences regarding force-merging vs tweaking the core test?

I can force-merge it later once there is no patch in CI (during weekend and quiet time) to avoid too much disruptions.

Suggestions to unblock […]:

  • force-merge
  • make the MediaWiki core test use +new Date() instead of Date.now() (could be reverted after the PageTriage change successfully merges)
  • get rid of date.js

Which of these options answers the question - Why did CI break now?

That’s still a mystery to me – I don’t plan to investigate that question further, though.

I can force-merge it later once there is no patch in CI (during weekend and quiet time) to avoid too much disruptions.

Done on master

Suggestions to unblock […]:

  • force-merge
  • make the MediaWiki core test use +new Date() instead of Date.now() (could be reverted after the PageTriage change successfully merges)
  • get rid of date.js

Which of these options answers the question - Why did CI break now?

Maybe T250932: Date.js external include breaks Date.now() (line 41) for modern javascript or T268513: PageTriage's external Date.js modifies/overwrites native JavaScript Date prototype, should be updated trigger this

Since the branch is not cut yet. I think we are out of the woods wrt the train but PageTriage being broken is something that needs fixing.

Change 755964 abandoned by Lucas Werkmeister (WMDE):

[mediawiki/core@master] DNM: Add more details to mw.now test

Reason:

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

Change 755965 abandoned by Lucas Werkmeister (WMDE):

[mediawiki/extensions/PageTriage@master] DNM: Test CI

Reason:

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

Zabe triaged this task as High priority.Jan 27 2022, 4:52 PM

Prevents merging of patches into mediawiki/extensions/PageTriage.

Change 730702 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/extensions/PageTriage@master] Replace deprecated date.js library with moment

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

Change 730702 merged by jenkins-bot:

[mediawiki/extensions/PageTriage@master] Replace deprecated date.js library with moment

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

taavi assigned this task to SD0001.