File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 11'use strict'
22
33// Use setImmediate() in Node.js to allow IO in between work
4+ /* istanbul ignore else: coverage currently does not include browsers */
45if ( typeof process !== 'undefined' && ! process . browser && typeof global !== 'undefined' && typeof global . setImmediate === 'function' ) {
56 const setImmediate = global . setImmediate
67
Original file line number Diff line number Diff line change @@ -38,3 +38,25 @@ test('throws on unsupported storeEncoding', function (t) {
3838 t . throws ( ( ) => new MemoryLevel ( { storeEncoding : 'foo' } ) , ( err ) => err . code === 'LEVEL_ENCODING_NOT_SUPPORTED' )
3939 t . end ( )
4040} )
41+
42+ test ( 'clear() waits a tick every 500 items' , async function ( t ) {
43+ const db = new MemoryLevel ( )
44+ const batch = Array ( 1000 )
45+
46+ for ( let i = 0 ; i < batch . length ; i ++ ) {
47+ batch [ i ] = { type : 'put' , key : i , value : i }
48+ }
49+
50+ await db . open ( )
51+ await db . batch ( batch )
52+
53+ t . is ( ( await db . keys ( ) . all ( ) ) . length , batch . length )
54+
55+ // This just checks that the code runs OK, not that it waits a
56+ // tick (TODO). Pass in a limit in order to use an iterator
57+ // instead of the fast-path of clear() that just deletes all.
58+ await db . clear ( { limit : batch . length * 2 } )
59+
60+ t . is ( ( await db . keys ( ) . all ( ) ) . length , 0 )
61+ return db . close ( )
62+ } )
You can’t perform that action at this time.
0 commit comments