File tree 2 files changed +13
-25
lines changed
2 files changed +13
-25
lines changed Original file line number Diff line number Diff line change 1
- module . exports = async function audit ( store , { dryRun = false } = { } ) {
2
- const stats = { cores : 0 , skipped : 0 , rootless : 0 , dropped : 0 }
3
-
1
+ module . exports = async function * audit ( store , { dryRun = false } = { } ) {
4
2
for await ( const { discoveryKey } of store . storage . createCoreStream ( ) ) {
5
- stats . cores ++
6
-
7
3
const core = store . get ( { discoveryKey, active : false } )
8
4
await core . ready ( )
9
5
10
- const audit = await core . core . audit ( { dryRun } )
6
+ yield { discoveryKey , key : core . key , audit : await core . core . audit ( { dryRun } ) }
11
7
12
8
try {
13
9
await core . close ( )
14
10
} catch {
15
11
// ignore if failed, we are auditing...
16
12
}
17
-
18
- if ( audit === null || audit . corrupt ) {
19
- stats . rootless ++
20
- continue
21
- }
22
-
23
- if ( audit . droppedTreeNodes || audit . droppedBlocks || audit . droppedBits ) {
24
- stats . dropped ++
25
- }
26
13
}
27
-
28
- return stats
29
14
}
Original file line number Diff line number Diff line change @@ -240,18 +240,21 @@ test('audit', async function (t) {
240
240
const d = store . get ( { name : 'another' } )
241
241
242
242
for ( let i = 0 ; i < 100 ; i ++ ) {
243
- await a . append ( i . toString ( ) )
244
- await b . append ( i . toString ( ) )
245
- await c . append ( i . toString ( ) )
243
+ if ( i < 20 ) await a . append ( i . toString ( ) )
244
+ if ( i < 40 ) await b . append ( i . toString ( ) )
245
+ if ( i < 80 ) await c . append ( i . toString ( ) )
246
246
await d . append ( i . toString ( ) )
247
247
}
248
248
249
- const result = await store . audit ( )
249
+ let n = 0
250
+ for await ( const { discoveryKey, audit } of store . audit ( ) ) {
251
+ n ++
252
+ if ( audit . droppedBits || audit . droppedBlocks || audit . droppedTreeNodes || audit . corrupt ) {
253
+ t . fail ( 'bad core' )
254
+ }
255
+ }
250
256
251
- t . is ( result . cores , 4 )
252
- t . is ( result . skipped , 0 )
253
- t . is ( result . rootless , 0 )
254
- t . is ( result . dropped , 0 )
257
+ t . is ( n , 4 )
255
258
256
259
await a . close ( )
257
260
await b . close ( )
You can’t perform that action at this time.
0 commit comments