From: jenkins-bot Date: Mon, 19 May 2014 11:31:57 +0000 (+0000) Subject: Merge "mediawiki.api: Do not cache errors in getToken()" X-Git-Tag: 1.31.0-rc.0~15661 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=a0dcdb49aad85293b0dc737b4e10b08b46ae415d;p=lhc%2Fweb%2Fwiklou.git Merge "mediawiki.api: Do not cache errors in getToken()" --- a0dcdb49aad85293b0dc737b4e10b08b46ae415d diff --cc tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js index 2cca7c8a68,83f5dd5663..f156c7285d --- a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js +++ b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js @@@ -127,22 -128,54 +128,54 @@@ // be added to user.tokens, use a fake one instead. api.getToken( 'testaction' ) .done( function ( token ) { - assert.ok( token.length, 'Got a token' ); + assert.ok( token.length, 'Got testaction token' ); } ) .fail( function ( err ) { - assert.equal( '', err, 'API error' ); + assert.equal( err, '', 'API error' ); + } ); + api.getToken( 'testaction' ) + .done( function ( token ) { + assert.ok( token.length, 'Got testaction token (cached)' ); + } ) + .fail( function ( err ) { + assert.equal( err, '', 'API error' ); } ); - assert.equal( this.server.requests.length, 1, 'Requests made' ); + // Don't cache error (bug 65268) + api.getToken( 'testaction2' ) + .fail( function ( err ) { + assert.equal( err, 'bite-me', 'Expected error' ); + } ) + .always( function () { + // Make this request after the first one has finished. + // If we make it simultaneously we still want it to share + // the cache, but as soon as it is fulfilled as error we + // reject it so that the next one tries fresh. + api.getToken( 'testaction2' ) + .done( function ( token ) { + assert.ok( token.length, 'Got testaction2 token (error was not be cached)' ); + } ) + .fail( function ( err ) { + assert.equal( err, '', 'API error' ); + } ); + + assert.equal( test.server.requests.length, 3, 'Requests made' ); + + test.server.requests[2].respond( 200, { 'Content-Type': 'application/json' }, + '{ "tokens": { "testaction2token": "0123abc" } }' + ); + } ); - this.server.respond( function ( request ) { - request.respond( 200, { 'Content-Type': 'application/json' }, - '{ "tokens": { "testactiontoken": "0123abc" } }' - ); - } ); + this.server.requests[0].respond( 200, { 'Content-Type': 'application/json' }, + '{ "tokens": { "testactiontoken": "0123abc" } }' + ); + + this.server.requests[1].respond( 200, { 'Content-Type': 'application/json' }, + '{ "error": { "code": "bite-me", "info": "Smite me, O Mighty Smiter" } }' + ); } ); - QUnit.test( 'postWithToken()', function ( assert ) { + QUnit.test( 'postWithToken( tokenType, params )', function ( assert ) { QUnit.expect( 1 ); var api = new mw.Api( { ajax: { url: '/postWithToken/api.php' } } );