From 7f139734b16a79e5bc1833712029c0586229c9f1 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 5 Apr 2024 13:25:12 +0300 Subject: [PATCH] [#133] scenarios: Support one-shot deletion scenario Signed-off-by: Evgenii Stratonikov --- scenarios/grpc.js | 32 +++++++++++++++++++++----------- scenarios/s3.js | 32 +++++++++++++++++++++----------- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/scenarios/grpc.js b/scenarios/grpc.js index 3ffc911..28ef12b 100644 --- a/scenarios/grpc.js +++ b/scenarios/grpc.js @@ -1,5 +1,6 @@ import {sleep} from 'k6'; import {SharedArray} from 'k6/data'; +import exec from 'k6/execution'; import logging from 'k6/x/frostfs/logging'; import native from 'k6/x/frostfs/native'; import registry from 'k6/x/frostfs/registry'; @@ -44,17 +45,6 @@ if (!!__ENV.METRIC_TAGS) { stats.setTags(__ENV.METRIC_TAGS) } -const delete_age = __ENV.DELETE_AGE ? parseInt(__ENV.DELETE_AGE) : undefined; -let obj_to_delete_selector = undefined; -if (registry_enabled && delete_age) { - obj_to_delete_selector = registry.getSelector( - __ENV.REGISTRY_FILE, 'obj_to_delete', - __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, { - status : 'created', - age : delete_age, - }); -} - const read_age = __ENV.READ_AGE ? parseInt(__ENV.READ_AGE) : 10; let obj_to_read_selector = undefined; if (registry_enabled) { @@ -81,6 +71,23 @@ if (write_vu_count > 0) { }; } +const delete_age = __ENV.DELETE_AGE ? parseInt(__ENV.DELETE_AGE) : undefined; +let obj_to_delete_selector = undefined; +let obj_to_delete_exit_on_null = undefined; +if (registry_enabled && delete_age) { + obj_to_delete_exit_on_null = write_vu_count == 0; + + let constructor = obj_to_delete_exit_on_null ? registry.getOneshotSelector + : registry.getSelector; + + obj_to_delete_selector = + constructor(__ENV.REGISTRY_FILE, 'obj_to_delete', + __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, { + status : 'created', + age : delete_age, + }); +} + const read_vu_count = parseInt(__ENV.READERS || '0'); if (read_vu_count > 0) { scenarios.read = { @@ -198,6 +205,9 @@ export function obj_delete() { const obj = obj_to_delete_selector.nextObject(); if (!obj) { + if (obj_to_delete_exit_on_null) { + exec.test.abort("No more objects to select"); + } return; } diff --git a/scenarios/s3.js b/scenarios/s3.js index 5c3e14a..22b031a 100644 --- a/scenarios/s3.js +++ b/scenarios/s3.js @@ -1,5 +1,6 @@ import {sleep} from 'k6'; import {SharedArray} from 'k6/data'; +import exec from 'k6/execution'; import logging from 'k6/x/frostfs/logging'; import registry from 'k6/x/frostfs/registry'; import s3 from 'k6/x/frostfs/s3'; @@ -44,17 +45,6 @@ if (!!__ENV.METRIC_TAGS) { stats.setTags(__ENV.METRIC_TAGS) } -const delete_age = __ENV.DELETE_AGE ? parseInt(__ENV.DELETE_AGE) : undefined; -let obj_to_delete_selector = undefined; -if (registry_enabled && delete_age) { - obj_to_delete_selector = registry.getSelector( - __ENV.REGISTRY_FILE, 'obj_to_delete', - __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, { - status : 'created', - age : delete_age, - }); -} - const read_age = __ENV.READ_AGE ? parseInt(__ENV.READ_AGE) : 10; let obj_to_read_selector = undefined; if (registry_enabled) { @@ -80,6 +70,23 @@ if (write_vu_count > 0) { }; } +const delete_age = __ENV.DELETE_AGE ? parseInt(__ENV.DELETE_AGE) : undefined; +let obj_to_delete_selector = undefined; +let obj_to_delete_exit_on_null = undefined; +if (registry_enabled && delete_age) { + obj_to_delete_exit_on_null = write_vu_count == 0; + + let constructor = obj_to_delete_exit_on_null ? registry.getOneshotSelector + : registry.getSelector; + + obj_to_delete_selector = + constructor(__ENV.REGISTRY_FILE, 'obj_to_delete', + __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, { + status : 'created', + age : delete_age, + }); +} + const read_vu_count = parseInt(__ENV.READERS || '0'); if (read_vu_count > 0) { scenarios.read = { @@ -196,6 +203,9 @@ export function obj_delete() { const obj = obj_to_delete_selector.nextObject(); if (!obj) { + if (obj_to_delete_exit_on_null) { + exec.test.abort("No more objects to select"); + } return; }