[#25] xk6: Read objects from registry for gRPC tests
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
50e2f55362
commit
3c26e7c917
8 changed files with 65 additions and 11 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue