Skip to content

Commit

Permalink
CR changes in all the file
Browse files Browse the repository at this point in the history
Signed-off-by: shirady <[email protected]>
  • Loading branch information
shirady committed Sep 24, 2024
1 parent a4c89ec commit 2c262f6
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/test/unit_tests/jest_tests/test_versioning_concurrency.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ describe('test versioning concurrency', () => {
it('multiple puts of the same key', async () => {
const bucket = 'bucket1';
const key = 'key1';
const failed_operations = [];
for (let i = 0; i < 5; i++) {
const random_data = Buffer.from(String(i));
const body = buffer_utils.buffer_to_read_stream(random_data);
nsfs.upload_object({ bucket: bucket, key: key, source_stream: body }, DUMMY_OBJECT_SDK).catch(err => console.log('multiple puts of the same key error - ', err));
nsfs.upload_object({ bucket: bucket, key: key, source_stream: body }, DUMMY_OBJECT_SDK)
.catch(err => failed_operations.push(err));
}
await P.delay(1000);
expect(failed_operations.length).toBe(0);
const versions = await nsfs.list_object_versions({ bucket: bucket }, DUMMY_OBJECT_SDK);
expect(versions.objects.length).toBe(5);
});
Expand All @@ -70,12 +73,14 @@ describe('test versioning concurrency', () => {

const mid_version_id = versions_arr[3];
const number_of_successful_operations = [];
const failed_operations = [];
for (let i = 0; i < 15; i++) {
nsfs.delete_object({ bucket: bucket, key: key, version_id: mid_version_id }, DUMMY_OBJECT_SDK)
.then(res => number_of_successful_operations.push(res))
.catch(err => console.log('delete the same key & version id error - ', err));
.catch(err => failed_operations.push(err));
}
await P.delay(1000);
expect(failed_operations.length).toBe(0);
expect(number_of_successful_operations.length).toBe(15);
});

Expand Down Expand Up @@ -150,21 +155,25 @@ describe('test versioning concurrency', () => {
const key = 'key4';
await _upload_versions(bucket, key, 1);

const successful_operations = [];
const successful_put_operations = [];
const successful_head_operations = [];
const failed_put_operations = [];
const failed_head_operations = [];
const number_of_iterations = 5; // by changing it to 10 it sometimes fails
for (let i = 0; i < number_of_iterations; i++) {
const random_data = Buffer.from(String(i));
const body = buffer_utils.buffer_to_read_stream(random_data);
nsfs.upload_object({ bucket: bucket, key: key, source_stream: body }, DUMMY_OBJECT_SDK)
.then(res => successful_operations.push(res))
.catch(err => console.log('multiple puts of the same key error - ', err));
.then(res => successful_put_operations.push(res))
.catch(err => failed_put_operations.push(err));
nsfs.read_object_md({ bucket: bucket, key: key }, DUMMY_OBJECT_SDK)
.then(res => successful_operations.push(res))
.catch(err => console.log('multiple heads of the same key error - ', err));
.then(res => successful_head_operations.push(res))
.catch(err => failed_head_operations.push(err));
}
await P.delay(1000);
const expected_number_of_successful_operations = number_of_iterations * 2;
expect(successful_operations.length).toBe(expected_number_of_successful_operations);
expect(failed_put_operations.length).toBe(0);
expect(failed_head_operations.length).toBe(0);
expect(successful_head_operations.length).toBe(number_of_iterations);
const versions = await nsfs.list_object_versions({ bucket: bucket }, DUMMY_OBJECT_SDK);
expect(versions.objects.length).toBe(number_of_iterations + 1); // 1 version before + 10 versions concurrent
});
Expand All @@ -182,7 +191,8 @@ async function _upload_versions(bucket, key, number_of_versions) {
for (let i = 0; i < number_of_versions; i++) {
const random_data = Buffer.from(String(i));
const body = buffer_utils.buffer_to_read_stream(random_data);
const res = await nsfs.upload_object({ bucket: bucket, key: key, source_stream: body }, DUMMY_OBJECT_SDK).catch(err => console.log('put error - ', err));
const res = await nsfs.upload_object({ bucket: bucket, key: key, source_stream: body }, DUMMY_OBJECT_SDK)
.catch(err => console.log('put error - ', err));
versions_arr.push(res.etag);
}
return versions_arr;
Expand Down

0 comments on commit 2c262f6

Please sign in to comment.