1 const MWBot
= require( 'mwbot' ),
2 Page
= require( './Page' ),
3 FRONTPAGE_REQUESTS_MAX_RUNS
= 10; // (arbitrary) safe-guard against endless execution
5 function getJobCount() {
7 apiUrl
: `${browser.options.baseUrl}/api.php`
9 return new Promise( ( resolve
) => {
14 } ).then( ( response
) => {
15 resolve( response
.query
.statistics
.jobs
);
20 function log( message
) {
21 process
.stdout
.write( `RunJobs ${message}\n` );
24 function runThroughFrontPageRequests( runCount
= 1 ) {
25 let page
= new Page();
26 log( `through requests to the front page (run ${runCount}).` );
30 return getJobCount().then( ( jobCount
) => {
31 if ( jobCount
=== 0 ) {
32 log( 'found no more queued jobs.' );
35 log( `detected ${jobCount} more queued job(s).` );
36 if ( runCount
>= FRONTPAGE_REQUESTS_MAX_RUNS
) {
37 log( 'stopping requests to the front page due to reached limit.' );
40 return runThroughFrontPageRequests( ++runCount
);
45 * Trigger the execution of jobs
47 * @see https://www.mediawiki.org/wiki/Manual:Job_queue/For_developers#Execution_of_jobs
49 * Use RunJobs.run() to ensure that jobs are executed before making assertions that depend on it.
51 * Systems that are selenium-tested are usually provisioned for that purpose, see no organic
52 * traffic, consequently typical post-send job queue processing rarely happens. Additionally,
53 * test set-up is often done through the API, requests to which do not trigger job queue
56 * This can lead to an accumulation of unprocessed jobs, which in turn would render certain
57 * assertions impossible - e.g. checking a page is listed on Special:RecentChanges right
60 * This class will try to trigger job execution through
61 * repeated blunt requests against the wiki's home page to trigger them at a rate
62 * of $wgJobRunRate per request.
68 return runThroughFrontPageRequests();
73 module
.exports
= RunJobs
;