From 3c26e7c91757332c45392ad5b0ff6144faee211d Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Wed, 19 Jul 2023 17:23:38 +0300 Subject: [PATCH] [#25] xk6: Read objects from registry for gRPC tests Signed-off-by: Dmitrii Stepanov --- internal/registry/obj_exporter.go | 2 +- internal/registry/obj_selector.go | 15 +++++++++++---- scenarios/grpc.js | 26 +++++++++++++++++++++++++- scenarios/grpc_car.js | 25 ++++++++++++++++++++++++- scenarios/local.js | 2 +- scenarios/s3.js | 2 +- scenarios/s3_car.js | 2 +- scenarios/verify.js | 2 +- 8 files changed, 65 insertions(+), 11 deletions(-) diff --git a/internal/registry/obj_exporter.go b/internal/registry/obj_exporter.go index 73cda60..675c192 100644 --- a/internal/registry/obj_exporter.go +++ b/internal/registry/obj_exporter.go @@ -45,7 +45,7 @@ func (o *ObjExporter) ExportJSONPreGen(fileName string) error { var comma string for i := 0; i < count; i++ { - info := o.selector.NextObject() + info := o.selector.NextObject(5) if info == nil { break } diff --git a/internal/registry/obj_selector.go b/internal/registry/obj_selector.go index 80f5192..ffec259 100644 --- a/internal/registry/obj_selector.go +++ b/internal/registry/obj_selector.go @@ -53,9 +53,15 @@ func NewObjSelector(registry *ObjRegistry, selectionSize int, filter *ObjFilter) // the following happens: // - a "new" next object is available; // - underlying registry context is done, nil objects will be returned on the -// currently blocked and every further NextObject calls. -func (o *ObjSelector) NextObject() *ObjectInfo { - return <-o.objChan +// currently blocked and every further NextObject calls; +// - timeoutSeconds elapsed, nil object will be returned. +func (o *ObjSelector) NextObject(timeoutSeconds int) *ObjectInfo { + select { + case <-time.After(time.Duration(timeoutSeconds) * time.Second): + return nil + case obj := <-o.objChan: + return obj + } } // Count returns total number of objects that match filter of the selector. @@ -163,10 +169,11 @@ func (o *ObjSelector) selectLoop() { if len(cache) != o.cacheSize { // no more objects, wait a little; the logic could be improved. select { - case <-time.After(time.Second * time.Duration(o.filter.Age/2)): + case <-time.After(time.Second): case <-o.ctx.Done(): return } + lastID = 0 } // clean handled objects diff --git a/scenarios/grpc.js b/scenarios/grpc.js index 328aae8..b41c4ed 100644 --- a/scenarios/grpc.js +++ b/scenarios/grpc.js @@ -49,6 +49,18 @@ if (registry_enabled && delete_age) { ); } +let obj_to_read_selector = undefined; +if (registry_enabled) { + obj_to_read_selector = registry.getSelector( + __ENV.REGISTRY_FILE, + "obj_to_read", + __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, + { + status: "created", + } + ) +} + const generator = datagen.generator(1024 * parseInt(__ENV.WRITE_OBJ_SIZE), __ENV.PAYLOAD_TYPE || ""); @@ -149,6 +161,18 @@ export function obj_read() { sleep(__ENV.SLEEP_READ); } + if(obj_to_read_selector) { + const obj = obj_to_read_selector.nextObject(5); + if (!obj) { + return; + } + const resp = grpc_client.get(obj.c_id, obj.o_id) + if (!resp.success) { + log.withFields({cid: obj.c_id, oid: obj.o_id}).error(resp.error); + } + return + } + const obj = obj_list[Math.floor(Math.random() * obj_list.length)]; const resp = grpc_client.get(obj.container, obj.object) if (!resp.success) { @@ -161,7 +185,7 @@ export function obj_delete() { sleep(__ENV.SLEEP_DELETE); } - const obj = obj_to_delete_selector.nextObject(); + const obj = obj_to_delete_selector.nextObject(5); if (!obj) { return; } diff --git a/scenarios/grpc_car.js b/scenarios/grpc_car.js index 2214529..972cbf9 100644 --- a/scenarios/grpc_car.js +++ b/scenarios/grpc_car.js @@ -49,6 +49,17 @@ if (registry_enabled && delete_age) { ); } +let obj_to_read_selector = undefined; +if (registry_enabled) { + obj_to_read_selector = registry.getSelector( + __ENV.REGISTRY_FILE, + "obj_to_read", + __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, + { + status: "created", + } + ) +} const generator = datagen.generator(1024 * parseInt(__ENV.WRITE_OBJ_SIZE)); @@ -174,6 +185,18 @@ export function obj_read() { sleep(__ENV.SLEEP_READ); } + if(obj_to_read_selector) { + const obj = obj_to_read_selector.nextObject(5); + if (!obj) { + return; + } + const resp = grpc_client.get(obj.c_id, obj.o_id) + if (!resp.success) { + log.withFields({cid: obj.c_id, oid: obj.o_id}).error(resp.error); + } + return + } + const obj = obj_list[Math.floor(Math.random() * obj_list.length)]; const resp = grpc_client.get(obj.container, obj.object) if (!resp.success) { @@ -186,7 +209,7 @@ export function obj_delete() { sleep(__ENV.SLEEP_DELETE); } - const obj = obj_to_delete_selector.nextObject(); + const obj = obj_to_delete_selector.nextObject(5); if (!obj) { return; } diff --git a/scenarios/local.js b/scenarios/local.js index 01496a4..c56d2bb 100644 --- a/scenarios/local.js +++ b/scenarios/local.js @@ -142,7 +142,7 @@ export function obj_read() { } export function obj_delete() { - const obj = obj_to_delete_selector.nextObject(); + const obj = obj_to_delete_selector.nextObject(5); if (!obj) { return; } diff --git a/scenarios/s3.js b/scenarios/s3.js index 0255364..e741708 100644 --- a/scenarios/s3.js +++ b/scenarios/s3.js @@ -157,7 +157,7 @@ export function obj_delete() { sleep(__ENV.SLEEP_DELETE); } - const obj = obj_to_delete_selector.nextObject(); + const obj = obj_to_delete_selector.nextObject(5); if (!obj) { return; } diff --git a/scenarios/s3_car.js b/scenarios/s3_car.js index 45b13fc..95edfd5 100644 --- a/scenarios/s3_car.js +++ b/scenarios/s3_car.js @@ -184,7 +184,7 @@ export function obj_delete() { sleep(__ENV.SLEEP_DELETE); } - const obj = obj_to_delete_selector.nextObject(); + const obj = obj_to_delete_selector.nextObject(5); if (!obj) { return; } diff --git a/scenarios/verify.js b/scenarios/verify.js index da27fed..3bba4d2 100644 --- a/scenarios/verify.js +++ b/scenarios/verify.js @@ -112,7 +112,7 @@ export function obj_verify() { sleep(__ENV.SLEEP); } - const obj = obj_to_verify_selector.nextObject(); + const obj = obj_to_verify_selector.nextObject(5); if (!obj) { log.info("All objects have been verified"); return;