File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
// Use setImmediate() in Node.js to allow IO in between work
4
+ /* istanbul ignore else: coverage currently does not include browsers */
4
5
if ( typeof process !== 'undefined' && ! process . browser && typeof global !== 'undefined' && typeof global . setImmediate === 'function' ) {
5
6
const setImmediate = global . setImmediate
6
7
Original file line number Diff line number Diff line change @@ -38,3 +38,25 @@ test('throws on unsupported storeEncoding', function (t) {
38
38
t . throws ( ( ) => new MemoryLevel ( { storeEncoding : 'foo' } ) , ( err ) => err . code === 'LEVEL_ENCODING_NOT_SUPPORTED' )
39
39
t . end ( )
40
40
} )
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