EBernhardson has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/392472 )
Change subject: Handle errors better in the tag tracker
......................................................................
Handle errors better in the tag tracker
When working on test sif you broke a tag all future
uses of the tag would just wait until cucumber
times them out, which is very painful. Rework
the tracking so it remembers failures.
Change-Id: I236780e30cab37884a569f0c6d27d11751fc4ee6
---
M tests/integration/features/support/hooks.js
M tests/integration/features/support/world.js
M tests/integration/lib/tracker.js
3 files changed, 46 insertions(+), 26 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch
refs/changes/72/392472/1
diff --git a/tests/integration/features/support/hooks.js
b/tests/integration/features/support/hooks.js
index 19fa8d0..45f18c1 100644
--- a/tests/integration/features/support/hooks.js
+++ b/tests/integration/features/support/hooks.js
@@ -12,9 +12,20 @@
const BeforeOnce = function ( options, fn ) {
Before( options, Promise.coroutine( function* () {
const status = yield this.tags.check( options.tags );
- if ( status === 'new' ) {
- yield fn.call( this );
+ if ( status === 'complete' ) {
+ return;
+ } else if ( status === 'new' ) {
+ try {
+ yield fn.call( this );
+ } catch ( err ) {
+ yield this.tags.reject( options.tags );
+ return;
+ }
yield this.tags.complete( options.tags );
+ } else if ( status === 'reject' ) {
+ throw new Error( 'Tag failed to initialize
previously' );
+ } else {
+ throw new Error( 'Unknown tag check status: ' +
status );
}
} ) );
};
diff --git a/tests/integration/features/support/world.js
b/tests/integration/features/support/world.js
index 7e8c9c2..9df4f45 100644
--- a/tests/integration/features/support/world.js
+++ b/tests/integration/features/support/world.js
@@ -12,6 +12,7 @@
*/
const {defineSupportCode} = require( 'cucumber' ),
net = require( 'net' ),
+ log = require( 'semlog' ).log,
Bot = require( 'mwbot' ),
StepHelpers = require( '../step_definitions/page_step_helpers' ),
Page = require( './pages/page' ),
@@ -29,7 +30,7 @@
this.pendingResponses = {};
this.connection.on( 'data', ( data ) => {
let parsed = JSON.parse( data );
- console.log( `received response for request
${parsed.requestId}: ${data}` );
+ log( `received response for request
${parsed.requestId}: ${data}` );
if ( parsed && this.pendingResponses[parsed.requestId]
) {
this.pendingResponses[parsed.requestId]( parsed
);
delete this.pendingResponses[parsed.requestId];
@@ -41,7 +42,7 @@
req.requestId = this.nextRequestId++;
return new Promise( ( resolve ) => {
let data = JSON.stringify( req );
- console.log( `Issuing request: ${data}` );
+ log( `Issuing request: ${data}` );
this.pendingResponses[req.requestId] = resolve;
this.connection.write( data );
} );
@@ -50,17 +51,27 @@
check( tag ) {
return Promise.coroutine( function* () {
if ( this.tags[tag] ) {
- return 'complete';
+ return this.tags[tag];
}
let response = yield this.request( {
check: tag
} );
- this.tags[tag] = true;
+ if ( response.status === 'complete' || response.status
=== 'reject' ) {
+ this.tags[tag] = response.status;
+ }
return response.status;
} ).call( this );
}
+ reject( tag ) {
+ this.tags[tag] = 'reject';
+ return this.request( {
+ reject: tag
+ } );
+ }
+
complete( tag ) {
+ this.tags[tag] = 'complete';
return this.request( {
complete: tag
} );
@@ -157,10 +168,10 @@
if ( !tmpUrl ) {
throw Error( `In "World.visit(page)" page is falsy:
page=${ page }` );
}
- console.log( `Visiting page: ${tmpUrl}` );
+ log( `Visiting page: ${tmpUrl}` );
browser.url( tmpUrl );
// logs full URL in case of typos, misplaced backslashes.
- console.log( `Visited page: ${browser.getUrl()}` );
+ log( `Visited page: ${browser.getUrl()}` );
};
// Variables held between steps and substituted into queries
diff --git a/tests/integration/lib/tracker.js b/tests/integration/lib/tracker.js
index 648022a..ab95c5d 100644
--- a/tests/integration/lib/tracker.js
+++ b/tests/integration/lib/tracker.js
@@ -87,31 +87,26 @@
}
dispatch( data ) {
- return new Promise( ( resolve ) => {
- if ( data.complete ) {
+ return new Promise( ( resolve, reject ) => {
+ if ( this.resolvers[data.complete] ) {
// tag completed, resolve pending
- if ( this.pending[data.complete] ) {
- this.resolvers[data.complete]( {
- tag: data.complete,
- status: 'complete'
- } );
- } else {
- // Happens if things are called out of
order. Not sure
- // why that would happen ... but
whatever.
- console.log( `Resolving tag
${data.complete} before it was requested` );
- this.resolvers[data.complete] = () =>
{};
- this.pending[data.complete] =
Promise.resolve( {
- tag: data.complete,
- status: 'complete'
- } );
- }
+ this.resolvers[data.complete]( {
+ tag: data.complete,
+ status: 'complete'
+ } );
// Just echo it back. Not used for anything.
+ resolve( data );
+ } else if ( this.resolvers[data.reject] ) {
+ this.resolvers[data.reject]( {
+ tag: data.reject,
+ status: 'reject'
+ } );
resolve( data );
} else if ( this.pending[data.check] ) {
// Another process is initializing this tag.
Wait for it
// to signal completion
this.pending[data.check].then( resolve );
- } else {
+ } else if ( data.check ) {
// New tag
this.pending[data.check] = new Promise( (
resolve ) => {
this.resolvers[data.check] = resolve;
@@ -120,6 +115,9 @@
tag: data.check,
status: 'new'
} );
+ } else {
+ console.log( 'Unrecognized tag server request:
', data );
+ reject();
}
} );
}
--
To view, visit https://gerrit.wikimedia.org/r/392472
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I236780e30cab37884a569f0c6d27d11751fc4ee6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits