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:
		| @@ -65,9 +65,11 @@ func New(address string, opts ...ClientOpt) (*Client, error) { | ||||
| 	} | ||||
|  | ||||
| 	gopts := []grpc.DialOption{ | ||||
| 		grpc.WithBlock(), | ||||
| 		grpc.WithInsecure(), | ||||
| 		grpc.WithTimeout(100 * time.Second), | ||||
| 		grpc.WithDialer(dialer), | ||||
| 		grpc.FailOnNonTempDialError(true), | ||||
| 	} | ||||
| 	if 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 { | ||||
| 		fmt.Fprintln(os.Stderr, err) | ||||
| 		os.Exit(1) | ||||
| 	} | ||||
| 	if err := waitForDaemonStart(ctx, client); err != nil { | ||||
| 		fmt.Fprintln(os.Stderr, err) | ||||
| 		fmt.Fprintln(os.Stderr, "immediate fail!", err) | ||||
| 		os.Exit(1) | ||||
| 	} | ||||
|  | ||||
| @@ -110,20 +106,26 @@ func TestMain(m *testing.M) { | ||||
| 	os.Exit(status) | ||||
| } | ||||
|  | ||||
| func waitForDaemonStart(ctx context.Context, client *Client) error { | ||||
| func waitForDaemonStart(ctx context.Context, address string) (*Client, error) { | ||||
| 	var ( | ||||
| 		client  *Client | ||||
| 		serving bool | ||||
| 		err     error | ||||
| 	) | ||||
|  | ||||
| 	for i := 0; i < 20; i++ { | ||||
| 		serving, err = client.IsServing(ctx) | ||||
| 		if serving { | ||||
| 			return nil | ||||
| 		if client == nil { | ||||
| 			client, err = New(address) | ||||
| 		} | ||||
| 		if err == nil { | ||||
| 			serving, err = client.IsServing(ctx) | ||||
| 			if serving { | ||||
| 				return client, nil | ||||
| 			} | ||||
| 		} | ||||
| 		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) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Derek McGowan
					Derek McGowan