Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testkit: give up on waiting for the RPC server to shutdown after 1s #8450

Merged
merged 2 commits into from
Apr 7, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion itests/kit/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/stretchr/testify/require"

Expand All @@ -25,7 +26,9 @@ func CreateRPCServer(t *testing.T, handler http.Handler, listener net.Listener)
}
testServ.Start()

t.Cleanup(testServ.Close)
t.Cleanup(func() {
waitUpTo(testServ.Close, time.Second, "Gave up waiting for RPC server to close after 1s")
})
t.Cleanup(testServ.CloseClientConnections)

addr := testServ.Listener.Addr()
Expand All @@ -34,6 +37,23 @@ func CreateRPCServer(t *testing.T, handler http.Handler, listener net.Listener)
return testServ, maddr
}

func waitUpTo(fn func(), waitTime time.Duration, errMsg string) {
ch := make(chan struct{})
go func() {
fn()
close(ch)
}()

timer := time.NewTimer(waitTime)
defer timer.Stop()
select {
case <-ch:
case <-timer.C:
fmt.Println(errMsg)
return
}
dirkmc marked this conversation as resolved.
Show resolved Hide resolved
}

func fullRpc(t *testing.T, f *TestFullNode) *TestFullNode {
handler, err := node.FullNodeHandler(f.FullNode, false)
require.NoError(t, err)
Expand Down