Skip to content

Commit

Permalink
Refresh soroban rpc client on every failure
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Jun 13, 2024
1 parent a0e7bbe commit 36c66c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
25 changes: 8 additions & 17 deletions cmd/soroban-rpc/internal/test/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"fmt"
"log"
"net"
"net/http"
"net/http/httptest"
Expand All @@ -15,7 +14,6 @@ import (
"os/signal"
"path"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -120,8 +118,6 @@ func NewTest(t *testing.T, cfg *TestConfig) *Test {
proxy.ServeHTTP(w, r)
}))

ch := jhttp.NewChannel(i.sorobanRPCURL(), nil)
i.rpcClient = jrpc2.NewClient(ch, nil)
rpcCfg := i.getRPConfig(sqlLitePath)
if i.rpcContainerVersion != "" {
i.rpcContainerConfigMountDir = i.createRPCContainerMountDir(rpcCfg)
Expand Down Expand Up @@ -243,34 +239,29 @@ func (i *Test) getRPConfig(sqlitePath string) map[string]string {
func (i *Test) waitForRPC() {
i.t.Log("Waiting for RPC to be healthy...")

// show if anybody is listening on RPC's port
outputListeningProc := func() {
fmt.Println("Who is listening on RPC port?")
cmd := exec.Command("lsof", "-i", fmt.Sprintf(":%d", sorobanRPCPort))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
require.NoError(i.t, cmd.Run())
// This is needed because if https://github.com/creachadair/jrpc2/issues/118
refreshClient := func() {
if i.rpcClient != nil {
i.rpcClient.Close()
}
ch := jhttp.NewChannel(i.sorobanRPCURL(), nil)
i.rpcClient = jrpc2.NewClient(ch, nil)
}

var result methods.HealthCheckResult
for t := 30; t >= 0; t-- {
refreshClient()
err := i.rpcClient.CallResult(context.Background(), "getHealth", nil, &result)
if err == nil {
if result.Status == "healthy" {
i.t.Log("RPC is healthy")
outputListeningProc()
return
}
}
i.t.Log("RPC still unhealthy", err, result.Status)
time.Sleep(time.Second)
}

outputListeningProc()
// Print stack trace and fail
buf := make([]byte, 1<<20)
stackSize := runtime.Stack(buf, true)
log.Printf("%s\n", string(buf[0:stackSize]))
i.t.Fatal("RPC failed to get healthy in 30 seconds")
}

Expand Down
1 change: 0 additions & 1 deletion cmd/soroban-rpc/internal/test/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
// We cannot test prior protocol versions since the Transaction XDR used for the test could be incompatible
// TODO: find a way to test migrations between protocols
func TestMigrate(t *testing.T) {
t.Skip("see if it works when we skip this test")
if GetCoreMaxSupportedProtocol() != MaxSupportedProtocolVersion {
t.Skip("Only test this for the latest protocol: ", MaxSupportedProtocolVersion)
}
Expand Down

0 comments on commit 36c66c6

Please sign in to comment.