@@ -244,6 +244,8 @@ mocha.describe('replication configuration bg worker tests', function() {
244
244
const bucket_for_replications = 'bucket5-br-bg' ;
245
245
const bucket_to_delete = 'bucket-to-delete' ;
246
246
const buckets = [ bucket1 , bucket2 , bucket_to_delete , bucket3 , bucket4 , bucket_for_replications ] ;
247
+ let uploaded_objects_count = 0 ;
248
+ let uploaded_prefix_objects_count = 0 ;
247
249
//const namespace_buckets = [];
248
250
let s3_owner ;
249
251
let scanner ;
@@ -255,6 +257,13 @@ mocha.describe('replication configuration bg worker tests', function() {
255
257
region : 'us-east-1' ,
256
258
httpOptions : { agent : new http . Agent ( { keepAlive : false } ) } ,
257
259
} ;
260
+
261
+ // Special character items to ensure encoding of URI works OK in the replication scanner
262
+ const special_character_items = [
263
+ 'key1273-2__#$!@%!#__BED-END-1-Carton-13.jpeg' ,
264
+ 'key1278-1__4267%2524__BED-END-1-Carton-13.jpeg'
265
+ ] ;
266
+
258
267
mocha . before ( 'init scanner & populate buckets' , async function ( ) {
259
268
// create buckets
260
269
await P . all ( _ . map ( buckets , async bucket_name => {
@@ -271,9 +280,23 @@ mocha.describe('replication configuration bg worker tests', function() {
271
280
// populate buckets
272
281
for ( let i = 0 ; i < 10 ; i ++ ) {
273
282
let key = `key${ i } ` ;
274
- if ( i % 2 === 0 ) key = 'pref' + key ;
283
+ if ( i % 2 === 0 ) {
284
+ key = 'pref' + key ;
285
+ uploaded_prefix_objects_count += 1 ;
286
+ }
275
287
await put_object ( s3_owner , bucket1 , key ) ;
288
+ uploaded_objects_count += 1 ;
276
289
}
290
+
291
+ // Add special characters items with prefix to the bucket
292
+ await Promise . all ( special_character_items . map ( item => put_object ( s3_owner , bucket1 , 'pref' + item ) ) ) ;
293
+ uploaded_objects_count += special_character_items . length ;
294
+
295
+ // Add special characters items without prefix to the bucket
296
+ await Promise . all ( special_character_items . map ( item => put_object ( s3_owner , bucket1 , item ) ) ) ;
297
+ uploaded_objects_count += special_character_items . length ;
298
+ uploaded_prefix_objects_count += special_character_items . length ;
299
+
277
300
cloud_utils . set_noobaa_s3_connection = ( ) => {
278
301
console . log ( 'setting connection to coretest endpoint and access key' ) ;
279
302
return s3_owner ;
@@ -293,11 +316,13 @@ mocha.describe('replication configuration bg worker tests', function() {
293
316
if ( i % 2 === 0 ) key = 'pref' + key ;
294
317
await delete_object ( s3_owner , bucket_name , key ) ;
295
318
}
319
+ await Promise . all ( special_character_items . map ( item => delete_object ( s3_owner , bucket_name , 'pref' + item ) ) ) ;
320
+ await Promise . all ( special_character_items . map ( item => delete_object ( s3_owner , bucket_name , item ) ) ) ;
296
321
await rpc_client . bucket . delete_bucket ( { name : bucket_name } ) ;
297
322
} ) ) ;
298
323
} ) ;
299
324
300
- mocha . it ( 'run replication scanner and wait - no replication - nothing to upload' , async function ( ) {
325
+ mocha . it ( 'run replication scanner and wait - no replication rule - nothing to upload' , async function ( ) {
301
326
const res1 = await scanner . run_batch ( ) ;
302
327
console . log ( 'waiting for replication objects no objects to upload' , res1 ) ;
303
328
await list_objects_and_wait ( s3_owner , bucket_for_replications , 0 ) ;
@@ -318,16 +343,16 @@ mocha.describe('replication configuration bg worker tests', function() {
318
343
[ { rule_id : 'rule-1' , destination_bucket : bucket_for_replications , filter : { prefix : 'pref' } } ] , false ) ;
319
344
let res1 = await scanner . run_batch ( ) ;
320
345
console . log ( 'waiting for replication objects - one rule one prefix' , res1 ) ;
321
- let contents = await list_objects_and_wait ( s3_owner , bucket_for_replications , 5 ) ;
346
+ let contents = await list_objects_and_wait ( s3_owner , bucket_for_replications , uploaded_prefix_objects_count ) ; //Check that the desired objects were replicated
322
347
console . log ( 'contents' , contents ) ;
323
348
324
349
// delete object from dst
325
350
await s3_owner . deleteObject ( { Bucket : bucket_for_replications , Key : contents [ 0 ] . Key } ) . promise ( ) ;
326
- await list_objects_and_wait ( s3_owner , bucket_for_replications , 4 ) ;
351
+ await list_objects_and_wait ( s3_owner , bucket_for_replications , uploaded_prefix_objects_count - 1 ) ; //Verify that one object was deleted
327
352
// sync again
328
353
res1 = await scanner . run_batch ( ) ;
329
354
console . log ( 'waiting for replication objects - one rule one prefix' , res1 ) ;
330
- contents = await list_objects_and_wait ( s3_owner , bucket_for_replications , 5 ) ;
355
+ contents = await list_objects_and_wait ( s3_owner , bucket_for_replications , uploaded_prefix_objects_count ) ; //Check that the delete object was replicate again
331
356
const key1 = contents [ 0 ] . Key ;
332
357
// override object in dst
333
358
const dst_obj1 = await s3_owner . getObject ( { Bucket : bucket_for_replications , Key : key1 } ) . promise ( ) ;
@@ -395,7 +420,7 @@ mocha.describe('replication configuration bg worker tests', function() {
395
420
} ) ;
396
421
397
422
mocha . it ( 'run replication scanner and wait - no prefix - all objects should be uploaded' , async function ( ) {
398
- const contents = await list_objects_and_wait ( s3_owner , bucket_for_replications , 5 ) ;
423
+ const contents = await list_objects_and_wait ( s3_owner , bucket_for_replications , uploaded_prefix_objects_count ) ;
399
424
for ( const content of contents ) {
400
425
const key = content . Key ;
401
426
await s3_owner . deleteObject ( { Bucket : bucket_for_replications , Key : key } ) . promise ( ) ;
@@ -404,7 +429,7 @@ mocha.describe('replication configuration bg worker tests', function() {
404
429
[ { rule_id : 'rule-1' , destination_bucket : bucket_for_replications } ] , false ) ;
405
430
const res1 = await scanner . run_batch ( ) ;
406
431
console . log ( 'waiting for replication objects - one rule no prefix' , res1 ) ;
407
- await list_objects_and_wait ( s3_owner , bucket_for_replications , 10 ) ;
432
+ await list_objects_and_wait ( s3_owner , bucket_for_replications , uploaded_objects_count ) ;
408
433
} ) ;
409
434
410
435
mocha . it ( 'run replication scanner and wait - 2 prefixes - all objects should be uploaded' , async function ( ) {
@@ -413,14 +438,14 @@ mocha.describe('replication configuration bg worker tests', function() {
413
438
{ rule_id : 'rule-2' , destination_bucket : bucket2 , filter : { prefix : 'pref' } }
414
439
] , false ) ;
415
440
416
- const res = await list_objects_and_wait ( s3_owner , bucket1 , 10 ) ;
441
+ const res = await list_objects_and_wait ( s3_owner , bucket1 , uploaded_objects_count ) ;
417
442
console . log ( 'waiting for replication objects original bucket ' , res ) ;
418
443
let res1 = await scanner . run_batch ( ) ;
419
444
console . log ( 'waiting for replication objects - 2 rules 1 prefix1 ' , res1 ) ;
420
- await list_objects_and_wait ( s3_owner , bucket2 , 5 ) ;
445
+ await list_objects_and_wait ( s3_owner , bucket2 , 5 + special_character_items . length ) ;
421
446
res1 = await scanner . run_batch ( ) ;
422
447
console . log ( 'waiting for replication objects - 2 rules 1 prefix2 ' , res1 ) ;
423
- await list_objects_and_wait ( s3_owner , bucket2 , 10 ) ;
448
+ await list_objects_and_wait ( s3_owner , bucket2 , uploaded_objects_count ) ;
424
449
} ) ;
425
450
426
451
mocha . it ( 'run replication scanner and wait - 2 buckets - all objects should be uploaded' , async function ( ) {
@@ -430,18 +455,20 @@ mocha.describe('replication configuration bg worker tests', function() {
430
455
] , false ) ;
431
456
432
457
await put_replication ( bucket2 ,
433
- [ { rule_id : 'rule-1' , destination_bucket : bucket4 , filter : { prefix : 'key' } } ,
434
- { rule_id : 'rule-2' , destination_bucket : bucket3 , filter : { prefix : 'pref' } }
458
+ [
459
+ { rule_id : 'rule-1' , destination_bucket : bucket4 , sync_versions : false , filter : { prefix : 'key' } } ,
460
+ { rule_id : 'rule-2' , destination_bucket : bucket3 , sync_versions : false , filter : { prefix : 'pref' } }
435
461
] , false ) ;
436
462
let res1 = await scanner . run_batch ( ) ;
437
463
console . log ( 'waiting for replication objects - 2 rules 1 prefix1 ' , res1 ) ;
438
- await list_objects_and_wait ( s3_owner , bucket3 , 5 ) ;
439
- await list_objects_and_wait ( s3_owner , bucket4 , 5 ) ;
464
+ await list_objects_and_wait ( s3_owner , bucket3 , 5 + special_character_items . length ) ;
465
+ await list_objects_and_wait ( s3_owner , bucket4 , uploaded_prefix_objects_count ) ;
440
466
441
467
res1 = await scanner . run_batch ( ) ;
442
468
console . log ( 'waiting for replication objects - 2 rules 1 prefix2 ' , res1 ) ;
443
- await list_objects_and_wait ( s3_owner , bucket3 , 10 ) ;
444
- await list_objects_and_wait ( s3_owner , bucket4 , 10 ) ;
469
+ // everything is uploaded by combination of above 2
470
+ await list_objects_and_wait ( s3_owner , bucket3 , uploaded_objects_count ) ;
471
+ await list_objects_and_wait ( s3_owner , bucket4 , uploaded_objects_count ) ;
445
472
} ) ;
446
473
447
474
} ) ;
0 commit comments