@@ -20,6 +20,7 @@ const { Glacier } = require('../../../sdk/glacier');
20
20
const { Semaphore } = require ( '../../../util/semaphore' ) ;
21
21
const nb_native = require ( '../../../util/nb_native' ) ;
22
22
const { handler : s3_get_bucket } = require ( '../../../endpoint/s3/ops/s3_get_bucket' ) ;
23
+ const Stream = require ( 'stream' ) ;
23
24
24
25
const inspect = ( x , max_arr = 5 ) => util . inspect ( x , { colors : true , depth : null , maxArrayLength : max_arr } ) ;
25
26
@@ -80,6 +81,12 @@ function assert_date(date, from, expected, tz = 'LOCAL') {
80
81
}
81
82
}
82
83
84
+ class NoOpWriteStream extends Stream . Writable {
85
+ _write ( chunk , encoding , callback ) {
86
+ callback ( ) ;
87
+ }
88
+ }
89
+
83
90
/* Justification: Disable max-lines-per-function for test functions
84
91
as it is not much helpful in the sense that "describe" function capture
85
92
entire test suite instead of being a logical abstraction */
@@ -198,42 +205,53 @@ mocha.describe('nsfs_glacier', function() {
198
205
assert ( found ) ;
199
206
} ) ;
200
207
201
- mocha . it ( 'restore-object should successfully restore' , async function ( ) {
208
+ mocha . it ( 'restore-object should successfully restore' , async function ( ) {
202
209
const now = Date . now ( ) ;
203
210
const data = crypto . randomBytes ( 100 ) ;
204
- const params = {
211
+ const params = {
205
212
bucket : upload_bkt ,
206
213
key : restore_key ,
207
- storage_class : s3_utils . STORAGE_CLASS_GLACIER ,
214
+ storage_class : s3_utils . STORAGE_CLASS_GLACIER ,
208
215
xattr,
209
- days : 1 ,
216
+ days : 1 ,
210
217
source_stream : buffer_utils . buffer_to_read_stream ( data )
211
218
} ;
212
219
213
220
const upload_res = await glacier_ns . upload_object ( params , dummy_object_sdk ) ;
214
221
console . log ( 'upload_object response' , inspect ( upload_res ) ) ;
215
222
216
- const restore_res = await glacier_ns . restore_object ( params , dummy_object_sdk ) ;
217
- assert ( restore_res ) ;
223
+ const dummy_stream_writer = new NoOpWriteStream ( ) ;
218
224
219
- // Issue restore
220
- await NamespaceFS . restore_wal . _process ( async file => {
221
- const fs_context = glacier_ns . prepare_fs_context ( dummy_object_sdk ) ;
222
- await backend . restore ( fs_context , file ) ;
225
+ // Ensure that we can't read the object before restore
226
+ await assert . rejects ( glacier_ns . read_object_stream ( params , dummy_object_sdk , dummy_stream_writer ) ) ;
223
227
224
- // Don't delete the file
225
- return false ;
226
- } ) ;
228
+ const restore_res = await glacier_ns . restore_object ( params , dummy_object_sdk ) ;
229
+ assert ( restore_res ) ;
230
+
231
+ // Ensure that we can't read the object before restore
232
+ await assert . rejects ( glacier_ns . read_object_stream ( params , dummy_object_sdk , dummy_stream_writer ) ) ;
233
+
234
+ // Issue restore
235
+ await NamespaceFS . restore_wal . _process ( async file => {
236
+ const fs_context = glacier_ns . prepare_fs_context ( dummy_object_sdk ) ;
237
+ await backend . restore ( fs_context , file ) ;
227
238
228
- // Ensure object is restored
229
- const md = await glacier_ns . read_object_md ( params , dummy_object_sdk ) ;
239
+ // Don't delete the file
240
+ return false ;
241
+ } ) ;
230
242
231
- assert ( ! md . restore_status . ongoing ) ;
243
+ // Ensure object is restored
244
+ const md = await glacier_ns . read_object_md ( params , dummy_object_sdk ) ;
232
245
233
- const expected_expiry = Glacier . generate_expiry ( new Date ( ) , params . days , '' , config . NSFS_GLACIER_EXPIRY_TZ ) ;
234
- assert ( expected_expiry . getTime ( ) >= md . restore_status . expiry_time . getTime ( ) ) ;
235
- assert ( now <= md . restore_status . expiry_time . getTime ( ) ) ;
236
- } ) ;
246
+ assert ( ! md . restore_status . ongoing ) ;
247
+
248
+ const expected_expiry = Glacier . generate_expiry ( new Date ( ) , params . days , '' , config . NSFS_GLACIER_EXPIRY_TZ ) ;
249
+ assert ( expected_expiry . getTime ( ) >= md . restore_status . expiry_time . getTime ( ) ) ;
250
+ assert ( now <= md . restore_status . expiry_time . getTime ( ) ) ;
251
+
252
+ // Ensure that we can't read the object before restore
253
+ await assert . doesNotReject ( glacier_ns . read_object_stream ( params , dummy_object_sdk , dummy_stream_writer ) ) ;
254
+ } ) ;
237
255
238
256
mocha . it ( 'restore-object should not restore failed item' , async function ( ) {
239
257
const now = Date . now ( ) ;
@@ -316,10 +334,10 @@ mocha.describe('nsfs_glacier', function() {
316
334
assert ( failure_stats . xattr [ Glacier . XATTR_RESTORE_REQUEST ] ) ;
317
335
} ) ;
318
336
319
- mocha . it ( '_finalize_restore should tolerate deleted objects' , async function ( ) {
337
+ mocha . it ( '_finalize_restore should tolerate deleted objects' , async function ( ) {
320
338
// should not throw error if the path does not exist
321
339
await backend . _finalize_restore ( glacier_ns . prepare_fs_context ( dummy_object_sdk ) , '/path/does/not/exist' ) ;
322
- } ) ;
340
+ } ) ;
323
341
324
342
mocha . it ( 'generate_expiry should round up the expiry' , function ( ) {
325
343
const now = new Date ( ) ;
0 commit comments