@@ -111,9 +111,11 @@ test('basic replication stats', async function (t) {
111111 t . is ( aStats . hotswaps , 0 , 'hotswaps init 0' )
112112 t . is ( aStats . invalidData , 0 , 'invalid data init 0' )
113113 t . is ( aStats . invalidRequests , 0 , 'invalid requests init 0' )
114+ t . is ( aStats . backoffs , 0 , 'backoffs init 0' )
115+ t . is ( aStats . notAvailableBackoffs , 0 , 'notAvailableBackoffs init 0' )
114116
115117 const initStatsLength = [ ...Object . keys ( aStats ) ] . length
116- t . is ( initStatsLength , 13 , 'Expected amount of stats' )
118+ t . is ( initStatsLength , 14 , 'Expected amount of stats' )
117119
118120 replicate ( a , b , t )
119121
@@ -2910,6 +2912,36 @@ test('local recovering from remote', async function (t) {
29102912 t . is ( b . length , a . length )
29112913} )
29122914
2915+ test ( 'backoff respected for NOT_AVAILABLE in case of incorrectly false remote bitfield)' , async function ( t ) {
2916+ const writer = await create ( t )
2917+
2918+ await writer . append ( [ 'a' , 'b' , 'c' , 'd' , 'e' ] )
2919+
2920+ const badBitfielder = await create ( t , writer . key )
2921+ const reader = await create ( t , writer . key )
2922+
2923+ replicate ( badBitfielder , writer , t )
2924+ await badBitfielder . get ( 0 )
2925+
2926+ t . is ( badBitfielder . core . bitfield . get ( 0 ) , true , 'sanity check' )
2927+ await badBitfielder . core . bitfield . set ( 0 , false ) // put incorrect bitfield
2928+
2929+ replicate ( badBitfielder , reader , t )
2930+
2931+ await t . exception (
2932+ async ( ) => reader . get ( 0 , { timeout : 500 } ) ,
2933+ / R E Q U E S T _ T I M E O U T / ,
2934+ 'cannot get the block due to bad bitfield'
2935+ )
2936+
2937+ t . is ( reader . replicator . stats . notAvailableBackoffs , 32 , 'paused after 32 attempts' )
2938+ t . ok (
2939+ badBitfielder . replicator . stats . wireRequest . rx < 40 ,
2940+ 'did not continue getting spammed (sanity check)'
2941+ )
2942+ t . ok ( reader . replicator . stats . wireRequest . tx < 40 , 'did not continue spamming (sanity check)' )
2943+ } )
2944+
29132945async function createAndDownload ( t , core ) {
29142946 const b = await create ( t , core . key )
29152947 replicate ( core , b , t , { teardown : false } )
0 commit comments