From 1fd29be532a15f7ab9c5430291533a1816635c17 Mon Sep 17 00:00:00 2001 From: yahya077 Date: Sun, 3 Mar 2024 20:25:37 +0300 Subject: [PATCH] elevator timeout example --- elevator/elevator.go | 2 ++ examples/yml_concurrent_example/integration.yml | 4 ++-- request.go | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/elevator/elevator.go b/elevator/elevator.go index 2f91595..49b7b5f 100644 --- a/elevator/elevator.go +++ b/elevator/elevator.go @@ -7,6 +7,7 @@ import ( "gopkg.in/yaml.v3" "os" "sync" + "time" ) func readYml(path string) ([]byte, error) { @@ -115,6 +116,7 @@ func (e *ElevatorEngine) WarmUp() IElevatorEngine { c, err := room.NewConnection( room.WithBaseUrl(r.Connection.BaseURL), room.WithDefaultHeader(room.NewHeader(room.NewMapStore(r.Connection.Headers))), + room.WithTimeout(time.Duration(r.Connection.Timeout)*time.Second), ) if err != nil { diff --git a/examples/yml_concurrent_example/integration.yml b/examples/yml_concurrent_example/integration.yml index e545ebf..4db2b3a 100644 --- a/examples/yml_concurrent_example/integration.yml +++ b/examples/yml_concurrent_example/integration.yml @@ -15,7 +15,7 @@ flat: todo1Room: connection: baseUrl: ${BASE_URL} - timeout: 15 + timeout: 1 # this request will timeout headers: Content-Type: "application/json" X-Type: "TODO - 2" @@ -23,7 +23,7 @@ flat: addTodo: concurrentKey: "add" method: "POST" - path: "todos/add" + path: "todos/add?delay=3000" todo2Room: connection: baseUrl: ${BASE_URL} diff --git a/request.go b/request.go index 24ab1b4..f18fa09 100644 --- a/request.go +++ b/request.go @@ -214,6 +214,9 @@ func (r *BaseRequest) PreRequest() IRequest { func (r *BaseRequest) SetConnectionConfig(connectionConfig IConnectionConfig) IRequest { r.connectionConfig = connectionConfig + + //TODO make an observer for changes of few fields + r.contextBuilder = NewContextBuilder(r.connectionConfig.TimeoutDuration()) return r }