DataValidator: properly chain queue
commit
071688159a
|
@ -227,8 +227,10 @@ module.exports = Class( 'DataValidator',
|
||||||
{
|
{
|
||||||
if ( this._pending )
|
if ( this._pending )
|
||||||
{
|
{
|
||||||
this._pending.then( callback );
|
// we become the end of the chain
|
||||||
return this._pending;
|
return this._pending = this._pending.then( () =>
|
||||||
|
this._onceReady( callback )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._pending = callback()
|
return this._pending = callback()
|
||||||
|
|
|
@ -325,32 +325,34 @@ describe( 'DataValidator', () =>
|
||||||
} );
|
} );
|
||||||
const { bstore } = getStore();
|
const { bstore } = getStore();
|
||||||
|
|
||||||
const faila = {};
|
// linked list (to previous)
|
||||||
const failb = {};
|
const fails = [ {}, {}, {} ];
|
||||||
|
fails.forEach( ( fail, i ) => fail.prev = fails[ i - 1 ] );
|
||||||
|
|
||||||
let running_first = true;
|
const failcalls = [];
|
||||||
|
|
||||||
vmonitor.update = ( _, fail ) =>
|
vmonitor.update = ( _, fail ) =>
|
||||||
{
|
{
|
||||||
if ( fail === failb )
|
failcalls.push( fail );
|
||||||
{
|
|
||||||
if ( running_first === true )
|
|
||||||
{
|
|
||||||
return Promise.reject( Error(
|
|
||||||
"Request not queued"
|
|
||||||
) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.resolve( true );
|
return Promise.resolve( true );
|
||||||
};
|
};
|
||||||
|
|
||||||
return Promise.all( [
|
return Promise.all( [
|
||||||
sut.updateFailures( {}, faila )
|
sut.updateFailures( {}, fails[ 0 ] )
|
||||||
.then( () => running_first = false ),
|
.then( () => expect( failcalls[ 0 ] ).to.equal( fails[ 0 ] ) ),
|
||||||
|
|
||||||
sut.updateFailures( {}, failb ),
|
sut.updateFailures( {}, fails[ 1 ] )
|
||||||
] );
|
.then( () => expect( failcalls[ 1 ] ).to.equal( fails[ 1 ] ) ),
|
||||||
|
|
||||||
|
sut.updateFailures( {}, fails[ 2 ] )
|
||||||
|
.then( () => expect( failcalls[ 2 ] ).to.equal( fails[ 2 ] ) ),
|
||||||
|
] )
|
||||||
|
.then( () => {
|
||||||
|
// sanity check to make sure the above stuff was
|
||||||
|
// actually called
|
||||||
|
expect( failcalls.length )
|
||||||
|
.to.equal( fails.length )
|
||||||
|
} );
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue