forked from TrueCloudLab/frostfs-sdk-go
[#343] client: Accept context parameter in Dial
In previous implementation of `Client.Dial` there was no ability to specify parent context (e.g. global application context). Add `PrmDial.SetContext` method which accepts optional base dial context. Use the context to open client connection or fall back to using `context.Background()`. Upgraded version of `github.com/nspcc-dev/neofs-api-go/v2` module also fixes the problem when dial timeout didn't work properly. Signed-off-by: Leonard Lyubich <ctulhurider@gmail.com>
This commit is contained in:
parent
1325b4f272
commit
452a50e9d5
4 changed files with 55 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"crypto/elliptic"
|
||||
"crypto/rand"
|
||||
|
@ -37,3 +38,31 @@ func newClient(server neoFSAPIServer) *Client {
|
|||
|
||||
return &c
|
||||
}
|
||||
|
||||
func TestClient_DialContext(t *testing.T) {
|
||||
var c Client
|
||||
|
||||
// try to connect to any host
|
||||
var prm PrmDial
|
||||
prm.SetServerURI("localhost:8080")
|
||||
|
||||
assert := func(ctx context.Context, errExpected error) {
|
||||
// use the particular context
|
||||
prm.SetContext(ctx)
|
||||
|
||||
// expect particular context error according to Dial docs
|
||||
require.ErrorIs(t, c.Dial(prm), errExpected)
|
||||
}
|
||||
|
||||
// create pre-abandoned context
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
assert(ctx, context.Canceled)
|
||||
|
||||
// create "pre-deadlined" context
|
||||
ctx, cancel = context.WithTimeout(context.Background(), 0)
|
||||
defer cancel()
|
||||
|
||||
assert(ctx, context.DeadlineExceeded)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue