Debian Codegraph @

tests/selenium/wdio-mediawiki/RunJobs.js

raw symbols SCIP
1 'use strict';
2
3 const MWBot = require( 'mwbot' );
4 const Page = require( './Page' );
5 const MAINPAGE_REQUESTS_MAX_RUNS = 10; // (arbitrary) safe-guard against endless execution
6
7 function getJobCount() {
8 const bot = new MWBot( {
9 apiUrl: `${ browser.config.baseUrl }/api.php`
10 } );
11 return bot.request( {
12 action: 'query',
13 meta: 'siteinfo',
14 siprop: 'statistics'
15 } ).then( ( response ) => response.query.statistics.jobs );
16 }
17
18 function log( message ) {
19 process.stdout.write( `RunJobs ${ message }\n` );
20 }
21
22 function runThroughMainPageRequests( runCount = 1 ) {
23 const page = new Page();
24 log( `through requests to the main page (run ${ runCount }).` );
25
26 page.openTitle( '' );
27
28 return getJobCount().then( ( jobCount ) => {
29 if ( jobCount === 0 ) {
30 log( 'found no more queued jobs.' );
31 return;
32 }
33 log( `detected ${ jobCount } more queued job(s).` );
34 if ( runCount >= MAINPAGE_REQUESTS_MAX_RUNS ) {
35 log( 'stopping requests to the main page due to reached limit.' );
36 return;
37 }
38 return runThroughMainPageRequests( ++runCount );
39 } );
40 }
41
42 /**
43 * Trigger the execution of jobs
44 *
45 * Use RunJobs.run() to ensure that jobs are executed before making assertions that depend on it.
46 *
47 * Systems that are selenium-tested are usually provisioned for that purpose, see no organic
48 * traffic, consequently typical post-send job queue processing rarely happens. Additionally,
49 * test set-up is often done through the API, requests to which do not trigger job queue
50 * processing at all.
51 *
52 * This can lead to an accumulation of unprocessed jobs, which in turn would render certain
53 * assertions impossible - e.g. checking a page is listed on Special:RecentChanges right
54 * after creating it.
55 *
56 * This class will try to trigger job execution through repeated blunt requests against the
57 * wiki's home page to trigger them at a rate of `$wgJobRunRate` per request.
58 *
59 * See also <https://www.mediawiki.org/wiki/Manual:Job_queue/For_developers#Execution_of_jobs>.
60 */
61 class RunJobs {
62
63 static run() {
64 browser.call( () => runThroughMainPageRequests() );
65 }
66 }
67
68 module.exports = RunJobs;