From 88b2129b541d10776724af38582334dfe3f41f88 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 21 Dec 2022 13:04:08 +0300 Subject: [PATCH] [#50] Allow to set timeouts for native scenario Signed-off-by: Evgenii Stratonikov (cherry picked from commit 1337eed6df45492f1045541021e8b14a42c5a286) --- internal/native/native.go | 6 ++++-- scenarios/grpc.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/native/native.go b/internal/native/native.go index 287bef2..e7ae4dc 100644 --- a/internal/native/native.go +++ b/internal/native/native.go @@ -51,7 +51,7 @@ func (n *Native) Exports() modules.Exports { return modules.Exports{Default: n} } -func (n *Native) Connect(endpoint, hexPrivateKey string) (*Client, error) { +func (n *Native) Connect(endpoint, hexPrivateKey string, dialTimeout, streamTimeout int) (*Client, error) { var ( cli client.Client pk *keys.PrivateKey @@ -73,7 +73,9 @@ func (n *Native) Connect(endpoint, hexPrivateKey string) (*Client, error) { var prmDial client.PrmDial prmDial.SetServerURI(endpoint) - prmDial.SetTimeout(5 * time.Second) + + prmDial.SetTimeout(time.Duration(dialTimeout) * time.Second) + prmDial.SetStreamTimeout(time.Duration(streamTimeout) * time.Second) err = cli.Dial(prmDial) if err != nil { diff --git a/scenarios/grpc.js b/scenarios/grpc.js index 0e19f53..e731171 100644 --- a/scenarios/grpc.js +++ b/scenarios/grpc.js @@ -17,7 +17,7 @@ const read_size = JSON.parse(open(__ENV.PREGEN_JSON)).obj_size; // Select random gRPC endpoint for current VU const grpc_endpoints = __ENV.GRPC_ENDPOINTS.split(','); const grpc_endpoint = grpc_endpoints[Math.floor(Math.random() * grpc_endpoints.length)]; -const grpc_client = native.connect(grpc_endpoint, ''); +const grpc_client = native.connect(grpc_endpoint, '', __ENV.DIAL_TIMEOUT ? parseInt(__ENV.DIAL_TIMEOUT) : 5, __ENV.STREAM_TIMEOUT ? parseInt(__ENV.STREAM_TIMEOUT) : 15); const registry_enabled = !!__ENV.REGISTRY_FILE; const obj_registry = registry_enabled ? registry.open(__ENV.REGISTRY_FILE) : undefined;