@@ -271,6 +271,8 @@ mocha.describe('replication configuration bg worker tests', function() {
271
271
const bucket_for_replications = 'bucket5-br-bg' ;
272
272
const bucket_to_delete = 'bucket-to-delete' ;
273
273
const buckets = [ bucket1 , bucket2 , bucket_to_delete , bucket3 , bucket4 , bucket_for_replications ] ;
274
+ let uploaded_objects_count = 0 ;
275
+ let uploaded_prefix_objects_count = 0 ;
274
276
//const namespace_buckets = [];
275
277
let s3_owner ;
276
278
let scanner ;
@@ -282,6 +284,13 @@ mocha.describe('replication configuration bg worker tests', function() {
282
284
region : 'us-east-1' ,
283
285
httpOptions : { agent : new http . Agent ( { keepAlive : false } ) } ,
284
286
} ;
287
+
288
+ // Special character items to ensure encoding of URI works OK in the replication scanner
289
+ const special_character_items = [
290
+ 'key1273-2__#$!@%!#__BED-END-1-Carton-13.jpeg' ,
291
+ 'key1278-1__4267%2524__BED-END-1-Carton-13.jpeg'
292
+ ] ;
293
+
285
294
mocha . before ( 'init scanner & populate buckets' , async function ( ) {
286
295
// create buckets
287
296
await P . all ( _ . map ( buckets , async bucket_name => {
@@ -298,9 +307,23 @@ mocha.describe('replication configuration bg worker tests', function() {
298
307
// populate buckets
299
308
for ( let i = 0 ; i < 10 ; i ++ ) {
300
309
let key = `key${ i } ` ;
301
- if ( i % 2 === 0 ) key = 'pref' + key ;
310
+ if ( i % 2 === 0 ) {
311
+ key = 'pref' + key ;
312
+ uploaded_prefix_objects_count += 1 ;
313
+ }
302
314
await put_object ( s3_owner , bucket1 , key ) ;
315
+ uploaded_objects_count += 1 ;
303
316
}
317
+
318
+ // Add special characters items with prefix to the bucket
319
+ await Promise . all ( special_character_items . map ( item => put_object ( s3_owner , bucket1 , 'pref' + item ) ) ) ;
320
+ uploaded_objects_count += special_character_items . length ;
321
+
322
+ // Add special characters items without prefix to the bucket
323
+ await Promise . all ( special_character_items . map ( item => put_object ( s3_owner , bucket1 , item ) ) ) ;
324
+ uploaded_objects_count += special_character_items . length ;
325
+ uploaded_prefix_objects_count += special_character_items . length ;
326
+
304
327
cloud_utils . set_noobaa_s3_connection = ( ) => {
305
328
console . log ( 'setting connection to coretest endpoint and access key' ) ;
306
329
return s3_owner ;
@@ -320,11 +343,13 @@ mocha.describe('replication configuration bg worker tests', function() {
320
343
if ( i % 2 === 0 ) key = 'pref' + key ;
321
344
await delete_object ( s3_owner , bucket_name , key ) ;
322
345
}
346
+ await Promise . all ( special_character_items . map ( item => delete_object ( s3_owner , bucket_name , 'pref' + item ) ) ) ;
347
+ await Promise . all ( special_character_items . map ( item => delete_object ( s3_owner , bucket_name , item ) ) ) ;
323
348
await rpc_client . bucket . delete_bucket ( { name : bucket_name } ) ;
324
349
} ) ) ;
325
350
} ) ;
326
351
327
- mocha . it ( 'run replication scanner and wait - no replication - nothing to upload' , async function ( ) {
352
+ mocha . it ( 'run replication scanner and wait - no replication rule - nothing to upload' , async function ( ) {
328
353
const res1 = await scanner . run_batch ( ) ;
329
354
console . log ( 'waiting for replication objects no objects to upload' , res1 ) ;
330
355
await _list_objects_and_wait ( s3_owner , bucket_for_replications , 0 ) ;
@@ -345,16 +370,16 @@ mocha.describe('replication configuration bg worker tests', function() {
345
370
[ { rule_id : 'rule-1' , destination_bucket : bucket_for_replications , sync_versions : false , filter : { prefix : 'pref' } } ] , false ) ;
346
371
let res1 = await scanner . run_batch ( ) ;
347
372
console . log ( 'waiting for replication objects - one rule one prefix' , res1 ) ;
348
- let contents = await _list_objects_and_wait ( s3_owner , bucket_for_replications , 5 ) ; //Check that the 5 objects were replicated
373
+ let contents = await _list_objects_and_wait ( s3_owner , bucket_for_replications , uploaded_prefix_objects_count ) ; //Check that the desired objects were replicated
349
374
console . log ( 'contents' , contents ) ;
350
375
351
376
// delete object from dst
352
377
await s3_owner . deleteObject ( { Bucket : bucket_for_replications , Key : contents [ 0 ] . Key } ) . promise ( ) ;
353
- await _list_objects_and_wait ( s3_owner , bucket_for_replications , 4 ) ; //Verify that the object was deleted
378
+ await _list_objects_and_wait ( s3_owner , bucket_for_replications , uploaded_prefix_objects_count - 1 ) ; //Verify that one object was deleted
354
379
// sync again
355
380
res1 = await scanner . run_batch ( ) ;
356
381
console . log ( 'waiting for replication objects - one rule one prefix' , res1 ) ;
357
- contents = await _list_objects_and_wait ( s3_owner , bucket_for_replications , 5 ) ; //Check that the delete object was replicate again
382
+ contents = await _list_objects_and_wait ( s3_owner , bucket_for_replications , uploaded_prefix_objects_count ) ; //Check that the delete object was replicate again
358
383
const key1 = contents [ 0 ] . Key ;
359
384
// override object in dst
360
385
const dst_obj1 = await s3_owner . getObject ( { Bucket : bucket_for_replications , Key : key1 } ) . promise ( ) ;
@@ -421,7 +446,7 @@ mocha.describe('replication configuration bg worker tests', function() {
421
446
} ) ;
422
447
423
448
mocha . it ( 'run replication scanner and wait - no prefix - all objects should be uploaded' , async function ( ) {
424
- const contents = await _list_objects_and_wait ( s3_owner , bucket_for_replications , 5 ) ;
449
+ const contents = await _list_objects_and_wait ( s3_owner , bucket_for_replications , uploaded_prefix_objects_count ) ;
425
450
for ( const content of contents ) {
426
451
const key = content . Key ;
427
452
await s3_owner . deleteObject ( { Bucket : bucket_for_replications , Key : key } ) . promise ( ) ;
@@ -430,7 +455,7 @@ mocha.describe('replication configuration bg worker tests', function() {
430
455
[ { rule_id : 'rule-1' , destination_bucket : bucket_for_replications , sync_versions : false } ] , false ) ;
431
456
const res1 = await scanner . run_batch ( ) ;
432
457
console . log ( 'waiting for replication objects - one rule no prefix' , res1 ) ;
433
- await _list_objects_and_wait ( s3_owner , bucket_for_replications , 10 ) ;
458
+ await _list_objects_and_wait ( s3_owner , bucket_for_replications , uploaded_objects_count ) ;
434
459
} ) ;
435
460
436
461
mocha . it ( 'run replication scanner and wait - 2 prefixes - all objects should be uploaded' , async function ( ) {
@@ -440,14 +465,14 @@ mocha.describe('replication configuration bg worker tests', function() {
440
465
{ rule_id : 'rule-2' , destination_bucket : bucket2 , sync_versions : false , filter : { prefix : 'pref' } }
441
466
] , false ) ;
442
467
443
- const res = await _list_objects_and_wait ( s3_owner , bucket1 , 10 ) ;
468
+ const res = await _list_objects_and_wait ( s3_owner , bucket1 , uploaded_objects_count ) ;
444
469
console . log ( 'waiting for replication objects original bucket ' , res ) ;
445
470
let res1 = await scanner . run_batch ( ) ;
446
471
console . log ( 'waiting for replication objects - 2 rules 1 prefix1 ' , res1 ) ;
447
- await _list_objects_and_wait ( s3_owner , bucket2 , 5 ) ;
472
+ await _list_objects_and_wait ( s3_owner , bucket2 , 5 + special_character_items . length ) ;
448
473
res1 = await scanner . run_batch ( ) ;
449
474
console . log ( 'waiting for replication objects - 2 rules 1 prefix2 ' , res1 ) ;
450
- await _list_objects_and_wait ( s3_owner , bucket2 , 10 ) ;
475
+ await _list_objects_and_wait ( s3_owner , bucket2 , uploaded_objects_count ) ;
451
476
} ) ;
452
477
453
478
mocha . it ( 'run replication scanner and wait - 2 buckets - all objects should be uploaded' , async function ( ) {
@@ -458,18 +483,20 @@ mocha.describe('replication configuration bg worker tests', function() {
458
483
] , false ) ;
459
484
460
485
await _put_replication ( bucket2 ,
461
- [ { rule_id : 'rule-1' , destination_bucket : bucket4 , sync_versions : false , filter : { prefix : 'key' } } ,
486
+ [
487
+ { rule_id : 'rule-1' , destination_bucket : bucket4 , sync_versions : false , filter : { prefix : 'key' } } ,
462
488
{ rule_id : 'rule-2' , destination_bucket : bucket3 , sync_versions : false , filter : { prefix : 'pref' } }
463
489
] , false ) ;
464
490
let res1 = await scanner . run_batch ( ) ;
465
491
console . log ( 'waiting for replication objects - 2 rules 1 prefix1 ' , res1 ) ;
466
- await _list_objects_and_wait ( s3_owner , bucket3 , 5 ) ;
467
- await _list_objects_and_wait ( s3_owner , bucket4 , 5 ) ;
492
+ await _list_objects_and_wait ( s3_owner , bucket3 , 5 + special_character_items . length ) ;
493
+ await _list_objects_and_wait ( s3_owner , bucket4 , uploaded_prefix_objects_count ) ;
468
494
469
495
res1 = await scanner . run_batch ( ) ;
470
496
console . log ( 'waiting for replication objects - 2 rules 1 prefix2 ' , res1 ) ;
471
- await _list_objects_and_wait ( s3_owner , bucket3 , 10 ) ;
472
- await _list_objects_and_wait ( s3_owner , bucket4 , 10 ) ;
497
+ // everything is uploaded by combination of above 2
498
+ await _list_objects_and_wait ( s3_owner , bucket3 , uploaded_objects_count ) ;
499
+ await _list_objects_and_wait ( s3_owner , bucket4 , uploaded_objects_count ) ;
473
500
} ) ;
474
501
475
502
} ) ;
0 commit comments