1 const MWBot
= require( 'mwbot' ),
2 Page
= require( './Page' ),
3 MAINPAGE_REQUESTS_MAX_RUNS
= 10; // (arbitrary) safe-guard against endless execution
5 function getJobCount() {
7 apiUrl
: `${browser.options.baseUrl}/api.php`
13 } ).then( ( response
) => {
14 return response
.query
.statistics
.jobs
;
18 function log( message
) {
19 process
.stdout
.write( `RunJobs ${message}\n` );
22 function runThroughMainPageRequests( runCount
= 1 ) {
23 let page
= new Page();
24 log( `through requests to the main page (run ${runCount}).` );
28 return getJobCount().then( ( jobCount
) => {
29 if ( jobCount
=== 0 ) {
30 log( 'found no more queued jobs.' );
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.' );
38 return runThroughMainPageRequests( ++runCount
);
43 * Trigger the execution of jobs
45 * @see https://www.mediawiki.org/wiki/Manual:Job_queue/For_developers#Execution_of_jobs
47 * Use RunJobs.run() to ensure that jobs are executed before making assertions that depend on it.
49 * Systems that are selenium-tested are usually provisioned for that purpose, see no organic
50 * traffic, consequently typical post-send job queue processing rarely happens. Additionally,
51 * test set-up is often done through the API, requests to which do not trigger job queue
54 * This can lead to an accumulation of unprocessed jobs, which in turn would render certain
55 * assertions impossible - e.g. checking a page is listed on Special:RecentChanges right
58 * This class will try to trigger job execution through
59 * repeated blunt requests against the wiki's home page to trigger them at a rate
60 * of $wgJobRunRate per request.
66 return runThroughMainPageRequests();
71 module
.exports
= RunJobs
;