-
Notifications
You must be signed in to change notification settings - Fork 32
/
wait_test.go
64 lines (51 loc) · 1.56 KB
/
wait_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package ginhelper_test
import (
"fmt"
"github.com/ipfs/go-log"
"github.com/phayes/freeport"
"github.com/stretchr/testify/suite"
"github.com/synapsecns/sanguine/core/ginhelper"
baseServer "github.com/synapsecns/sanguine/core/server"
"github.com/synapsecns/sanguine/core/testsuite"
"testing"
"time"
)
// WaitSuite defines the basic test suite.
type WaitSuite struct {
*testsuite.TestSuite
}
// NewTestSuite creates a new test suite and performs some basic checks afterward.
// Every test suite in the synapse library should inherit from this suite and override where necessary.
func NewUtilSuite(tb testing.TB) *WaitSuite {
tb.Helper()
return &WaitSuite{
testsuite.NewTestSuite(tb),
}
}
func TestUtilSuite(t *testing.T) {
suite.Run(t, NewUtilSuite(t))
}
func (t *WaitSuite) TearDownTest() {
ginhelper.ResetServerTimeout()
}
func (t *WaitSuite) TestWaitForStartFail() {
port, err := freeport.GetFreePort()
t.Require().NoError(err)
ginhelper.SetServerTimeout(time.Millisecond)
// make sure this errors on non existent server
t.Require().NotNil(ginhelper.WaitForStart(t.GetTestContext(), port))
}
// make sure a working server passes.
func (t *WaitSuite) TestWaitForStartSucceed() {
testLogger := log.Logger("test")
tmpPort, err := freeport.GetFreePort()
t.Require().NoError(err)
router := ginhelper.New(testLogger)
// start a server
go func() {
connection := baseServer.Server{}
_ = connection.ListenAndServe(t.GetTestContext(), fmt.Sprintf(":%d", tmpPort), router)
}()
err = ginhelper.WaitForStart(t.GetTestContext(), tmpPort)
t.Require().NoError(err)
}