From 1acff763b4112855967f0bc8e944a9735e031044 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Mon, 3 May 2021 21:13:19 +0100
Subject: [PATCH] Wait for etcd GRPC connection to be established in radioctl

---
 cmd/radioctl/radioctl.go | 2 ++
 node/node_test.go        | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/cmd/radioctl/radioctl.go b/cmd/radioctl/radioctl.go
index c1303efc..57406d2e 100644
--- a/cmd/radioctl/radioctl.go
+++ b/cmd/radioctl/radioctl.go
@@ -17,6 +17,7 @@ import (
 	pb "git.autistici.org/ale/autoradio/proto"
 	"github.com/google/subcommands"
 	"go.etcd.io/etcd/client/v3"
+	"google.golang.org/grpc"
 )
 
 // Format for output of structured data.
@@ -86,6 +87,7 @@ func getClient() *client.Client {
 	if auClient == nil {
 		cli, err := clientv3.New(clientv3.Config{
 			Endpoints:   strings.Split(*etcdEndpoints, ","),
+			DialOptions: []grpc.DialOption{grpc.WithBlock()},
 			DialTimeout: 5 * time.Second,
 		})
 		if err != nil {
diff --git a/node/node_test.go b/node/node_test.go
index 23ded5a1..f2b316d0 100644
--- a/node/node_test.go
+++ b/node/node_test.go
@@ -17,6 +17,7 @@ import (
 	"go.etcd.io/etcd/client/v3"
 	"go.etcd.io/etcd/client/v3/concurrency"
 	"go.etcd.io/etcd/server/v3/embed"
+	"google.golang.org/grpc"
 	"google.golang.org/protobuf/proto"
 )
 
@@ -42,7 +43,8 @@ func createTestEtcd(t testing.TB) (*clientv3.Client, func()) {
 	<-e.Server.ReadyNotify()
 
 	cli, err := clientv3.New(clientv3.Config{
-		Endpoints: []string{"http://localhost:2379"},
+		Endpoints:   []string{"http://localhost:2379"},
+		DialOptions: []grpc.DialOption{grpc.WithBlock()},
 	})
 	if err != nil {
 		t.Fatalf("clientv3.New: %v", err)
-- 
GitLab