Skip to content

Commit

Permalink
test: capture gcosmos gRPC address
Browse files Browse the repository at this point in the history
We are able to connect to a valid address with this setup, but I am
still working out some client request issues.
  • Loading branch information
mark-rushakoff committed Nov 8, 2024
1 parent 7bf4f1c commit 83814dc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 27 additions & 1 deletion helpers_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func ConfigureChain(t *testing.T, ctx context.Context, cfg ChainConfig) Chain {

type ChainAddresses struct {
HTTP []string
// TODO: this can also include GRPC when we need it.
GRPC []string

// File containing the address of the seed node.
// Only populated for chains with multiple validators.
Expand All @@ -240,6 +240,7 @@ func (c Chain) Start(t *testing.T, ctx context.Context, nVals int) ChainAddresse

ca := ChainAddresses{
HTTP: make([]string, nVals),
GRPC: make([]string, nVals),
}

addrDir := t.TempDir()
Expand Down Expand Up @@ -356,6 +357,31 @@ func (c Chain) Start(t *testing.T, ctx context.Context, nVals int) ChainAddresse
}

ca.HTTP[i] = httpAddr

var grpcAddr string
deadline = time.Now().Add(5 * time.Second)
for time.Now().Before(deadline) {
a, err := os.ReadFile(grpcAddrFiles[i])
if err != nil {
// Swallow the error and delay.
time.Sleep(25 * time.Millisecond)
continue
}
if !bytes.HasSuffix(a, []byte("\n")) {
// Very unlikely incomplete write/read.
time.Sleep(25 * time.Millisecond)
continue
}

grpcAddr = strings.TrimSuffix(string(a), "\n")
break
}

if grpcAddr == "" {
t.Fatalf("did not read grpc address from %s in time", grpcAddrFiles[i])
}

ca.GRPC[i] = grpcAddr
}

return ca
Expand Down
3 changes: 3 additions & 0 deletions internal/gci/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ func NewGcosmosCommand(
rootCmd.PersistentFlags().String("from", "", "TODO: don't set this in internal/gci/command.go")
rootCmd.PersistentFlags().Bool("generate-only", false, "TODO: don't set this in internal/gci/command.go")

rootCmd.PersistentFlags().String("grpc-addr", "", "TODO: don't set this in internal/gci/command.go")
rootCmd.PersistentFlags().String("grpc-insecure", "", "TODO: don't set this in internal/gci/command.go")

subCommand, configMap, logger, err := factory.ParseCommand(rootCmd, args)
if err != nil {
panic(fmt.Errorf("failed to parse command [args=%#v]: %w", args, err))
Expand Down

0 comments on commit 83814dc

Please sign in to comment.