Skip to content

Commit

Permalink
Merge pull request #8450 from filecoin-project/fix/testkit-rpc-shutdown
Browse files Browse the repository at this point in the history
testkit: give up on waiting for the RPC server to shutdown after 1s
  • Loading branch information
magik6k authored Apr 7, 2022
2 parents f652dd3 + c34ade9 commit b26ac2b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 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,21 @@ 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)
}()

select {
case <-ch:
case <-time.After(waitTime):
fmt.Println(errMsg)
return
}
}

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

0 comments on commit b26ac2b

Please sign in to comment.