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