Add with block and fail on non-temp dial error
This guarantees that grpc requests will fail quickly when the service is not started or does not have permission. Without the fail on non-temp error the withblock will cause the client to wait until the timeout before failing. Fixes #989 Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
parent
6bbed2c125
commit
64bc516bbe
@ -65,9 +65,11 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gopts := []grpc.DialOption{
|
gopts := []grpc.DialOption{
|
||||||
|
grpc.WithBlock(),
|
||||||
grpc.WithInsecure(),
|
grpc.WithInsecure(),
|
||||||
grpc.WithTimeout(100 * time.Second),
|
grpc.WithTimeout(100 * time.Second),
|
||||||
grpc.WithDialer(dialer),
|
grpc.WithDialer(dialer),
|
||||||
|
grpc.FailOnNonTempDialError(true),
|
||||||
}
|
}
|
||||||
if copts.defaultns != "" {
|
if copts.defaultns != "" {
|
||||||
unary, stream := newNSInterceptors(copts.defaultns)
|
unary, stream := newNSInterceptors(copts.defaultns)
|
||||||
|
@ -67,13 +67,9 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := New(address)
|
client, err := waitForDaemonStart(ctx, address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, "immediate fail!", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
if err := waitForDaemonStart(ctx, client); err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,20 +106,26 @@ func TestMain(m *testing.M) {
|
|||||||
os.Exit(status)
|
os.Exit(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitForDaemonStart(ctx context.Context, client *Client) error {
|
func waitForDaemonStart(ctx context.Context, address string) (*Client, error) {
|
||||||
var (
|
var (
|
||||||
|
client *Client
|
||||||
serving bool
|
serving bool
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
for i := 0; i < 20; i++ {
|
for i := 0; i < 20; i++ {
|
||||||
serving, err = client.IsServing(ctx)
|
if client == nil {
|
||||||
if serving {
|
client, err = New(address)
|
||||||
return nil
|
}
|
||||||
|
if err == nil {
|
||||||
|
serving, err = client.IsServing(ctx)
|
||||||
|
if serving {
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("containerd did not start within 2s: %v", err)
|
return nil, fmt.Errorf("containerd did not start within 2s: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewClient(t *testing.T) {
|
func TestNewClient(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user