Skip to content

Commit

Permalink
fixes #322 Test case for reconnect retry should be skipped
Browse files Browse the repository at this point in the history
fixes #321 Use dynamically determined IPC paths in tests

These are changes in the test suite to make it more robust and
reliable in CI/CD.
  • Loading branch information
gdamore committed Jun 24, 2018
1 parent 8880aff commit 52bc424
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 42 deletions.
2 changes: 1 addition & 1 deletion test/besteffort_test.go
Expand Up @@ -70,6 +70,6 @@ func testBestEffort(addr string, tran mangos.Transport) {

func TestBestEffortTCP(t *testing.T) {
Convey("Testing TCP Best Effort", t, func() {
testBestEffort(AddrTestTCP, tcp.NewTransport())
testBestEffort(AddrTestTCP(), tcp.NewTransport())
})
}
4 changes: 2 additions & 2 deletions test/busnonblock_test.go
@@ -1,4 +1,4 @@
// Copyright 2016 The Mangos Authors
// Copyright 2018 The Mangos Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use file except in compliance with the License.
Expand Down Expand Up @@ -59,6 +59,6 @@ func testBusNonBlock(addr string, tran mangos.Transport) {

func TestBusNonBlockTCP(t *testing.T) {
Convey("Testing Bus Send (TCP) is Non-Blocking", t, func() {
testBusNonBlock(AddrTestTCP, tcp.NewTransport())
testBusNonBlock(AddrTestTCP(), tcp.NewTransport())
})
}
56 changes: 38 additions & 18 deletions test/common_test.go
Expand Up @@ -619,50 +619,70 @@ func RunTests(t *testing.T, addr string, cases []TestCase) {

// We have to expose these, so that device tests can use them.

// AddrTestTCP is a suitable TCP address for testing.
var AddrTestTCP = "tcp://127.0.0.1:59093"
var currPort uint16
var currLock sync.Mutex

// AddrTestIPC is a suitable IPC address for testing.
var AddrTestIPC = "ipc://MYTEST_IPC_SOCK"
func init() {
currPort = uint16(time.Now().UnixNano()%20000 + 20000)
}

func NextPort() uint16 {
currLock.Lock()
defer currLock.Unlock()
p := currPort
currPort++
return p
}

func AddrTestIPC() string {
return (fmt.Sprintf("ipc://mangostest%d", NextPort()))
}

// AddrTestInp is a suitable Inproc address for testing.
var AddrTestInp = "inproc://MYTEST_INPROC"
func AddrTestWSS() string {
return (fmt.Sprintf("wss://127.0.0.1:%d/", NextPort()))
}

// AddrTestTLS is a suitable TLS address for testing.
var AddrTestTLS = "tls+tcp://127.0.0.1:63934"
func AddrTestWS() string {
return (fmt.Sprintf("ws://127.0.0.1:%d/", NextPort()))
}
func AddrTestTCP() string {
return (fmt.Sprintf("tcp://127.0.0.1:%d", NextPort()))
}

// AddrTestWS is a suitable websocket address for testing.
var AddrTestWS = "ws://127.0.0.1:63935/"
func AddrTestTLS() string {
return (fmt.Sprintf("tls+tcp://127.0.0.1:%d", NextPort()))
}

// AddrTestWSS is a suitable secure websocket address for testing.
var AddrTestWSS = "wss://127.0.0.1:63936/"
func AddrTestInp() string {
return (fmt.Sprintf("inproc://test_%d", NextPort()))
}

// RunTestsTCP runs the TCP tests.
func RunTestsTCP(t *testing.T, cases []TestCase) {
RunTests(t, AddrTestTCP, cases)
RunTests(t, AddrTestTCP(), cases)
}

// RunTestsIPC runs the IPC tests.
func RunTestsIPC(t *testing.T, cases []TestCase) {
RunTests(t, AddrTestIPC, cases)
RunTests(t, AddrTestIPC(), cases)
}

// RunTestsInp runs the inproc tests.
func RunTestsInp(t *testing.T, cases []TestCase) {
RunTests(t, AddrTestInp, cases)
RunTests(t, AddrTestInp(), cases)
}

// RunTestsTLS runs the TLS tests.
func RunTestsTLS(t *testing.T, cases []TestCase) {
RunTests(t, AddrTestTLS, cases)
RunTests(t, AddrTestTLS(), cases)
}

// RunTestsWS runs the websock tests.
func RunTestsWS(t *testing.T, cases []TestCase) {
RunTests(t, AddrTestWS, cases)
RunTests(t, AddrTestWS(), cases)
}

// RunTestsWSS runs the websock tests.
func RunTestsWSS(t *testing.T, cases []TestCase) {
RunTests(t, AddrTestWSS, cases)
RunTests(t, AddrTestWSS(), cases)
}
14 changes: 7 additions & 7 deletions test/device_test.go
Expand Up @@ -279,31 +279,31 @@ func testDevChain(t *testing.T, addr1 string, addr2 string, addr3 string) {
}

func TestDeviceChain(t *testing.T) {
testDevChain(t, AddrTestTCP, AddrTestWS, AddrTestInp)
testDevChain(t, AddrTestTCP(), AddrTestWS(), AddrTestInp())
// Some platforms (windows) need a little time to wind up the close
time.Sleep(100 * time.Millisecond)
}

func TestDeviceLoopTCP(t *testing.T) {
testDevLoop(t, AddrTestTCP)
testDevLoop(t, AddrTestTCP())
}

func TestDeviceLoopInp(t *testing.T) {
testDevLoop(t, AddrTestInp)
testDevLoop(t, AddrTestInp())
}

func TestDeviceLoopIPC(t *testing.T) {
testDevLoop(t, AddrTestIPC)
testDevLoop(t, AddrTestIPC())
}

func TestDeviceLoopTLS(t *testing.T) {
testDevLoop(t, AddrTestTLS)
testDevLoop(t, AddrTestTLS())
}

func TestDeviceLoopWS(t *testing.T) {
testDevLoop(t, AddrTestWS)
testDevLoop(t, AddrTestWS())
}

func TestDeviceLoopWSS(t *testing.T) {
testDevLoop(t, AddrTestWSS)
testDevLoop(t, AddrTestWSS())
}
2 changes: 1 addition & 1 deletion test/expire_test.go
Expand Up @@ -27,7 +27,7 @@ import (

func TestExpireDrop(t *testing.T) {
inp := inproc.NewTransport()
addr := AddrTestInp + "EXPIRE"
addr := AddrTestInp()

if runtime.GOOS == "windows" {
t.Skip("Windows clock resolution too coarse")
Expand Down
4 changes: 2 additions & 2 deletions test/maxrx_test.go
Expand Up @@ -190,9 +190,9 @@ func testMaxRx(t *testing.T, addr string, tran mangos.Transport) {
}

func TestMaxRxTCP(t *testing.T) {
testMaxRx(t, AddrTestTCP, tcp.NewTransport())
testMaxRx(t, AddrTestTCP(), tcp.NewTransport())
}

func TestMaxRxWS(t *testing.T) {
testMaxRx(t, AddrTestWS, ws.NewTransport())
testMaxRx(t, AddrTestWS(), ws.NewTransport())
}
2 changes: 1 addition & 1 deletion test/porthook_test.go
Expand Up @@ -81,7 +81,7 @@ func TestPortHook(t *testing.T) {
srvtest := &hooktest{allow: true, t: t}
clitest := &hooktest{allow: true, t: t}

addr := AddrTestTCP
addr := AddrTestTCP()

srvtest.expect = []hookinfo{{
action: mangos.PortActionAdd,
Expand Down
2 changes: 1 addition & 1 deletion test/pubnonblock_test.go
Expand Up @@ -60,6 +60,6 @@ func testPubNonBlock(addr string, tran mangos.Transport) {

func TestPubNonBlockTCP(t *testing.T) {
Convey("Testing Pub Send (TCP) is Non-Blocking", t, func() {
testPubNonBlock(AddrTestTCP, tcp.NewTransport())
testPubNonBlock(AddrTestTCP(), tcp.NewTransport())
})
}
12 changes: 9 additions & 3 deletions test/reqretry_test.go
Expand Up @@ -29,7 +29,8 @@ import (

func TestReqRetry(t *testing.T) {
Convey("Testing Req Retry", t, func() {
addr := "inproc://port"
//addr := "inproc://port"
addr := AddrTestInp()

// Let's first try request issued with no connection, and
// completing immediately after connect is established.
Expand All @@ -52,6 +53,9 @@ func TestReqRetry(t *testing.T) {
So(err, ShouldBeNil)
So(d, ShouldNotBeNil)

err = sockreq.SetOption(mangos.OptionReconnectTime, time.Millisecond*100)
So(err, ShouldBeNil)

l, err := sockrep.NewListener(addr, nil)
So(err, ShouldBeNil)
So(l, ShouldNotBeNil)
Expand Down Expand Up @@ -83,7 +87,9 @@ func TestReqRetry(t *testing.T) {
m.Free()
})

Convey("A request is reissued on server re-connect", func() {
// Following is skipped for now because of the backout
// of e5e6478f44cda1eb8427b590755270e2704a990d
SkipConvey("A request is reissued on server re-connect", func() {

rep2, err := rep.NewSocket()
So(err, ShouldBeNil)
Expand All @@ -110,8 +116,8 @@ func TestReqRetry(t *testing.T) {
So(err, ShouldBeNil)

// Now close the connection -- no reply!
sockrep.Close()
l.Close()
sockrep.Close()

// Open the new one on the other socket
err = l2.Listen()
Expand Down
6 changes: 4 additions & 2 deletions test/simple_test.go
Expand Up @@ -46,10 +46,12 @@ func TestSimpleCorrect(t *testing.T) {
rx.AddTransport(tcp.NewTransport())

Convey("When a simple TCP pair is created", func() {
e = rx.Listen(AddrTestTCP)

a := AddrTestTCP()
e = rx.Listen(a)
So(e, ShouldBeNil)

e = tx.Dial(AddrTestTCP)
e = tx.Dial(a)
So(e, ShouldBeNil)

iter := 100000
Expand Down
2 changes: 1 addition & 1 deletion test/starnonblock_test.go
Expand Up @@ -60,6 +60,6 @@ func testStarNonBlock(addr string, tran mangos.Transport) {

func TestStarNonBlockTCP(t *testing.T) {
Convey("Testing STAR Send (TCP) is Non-Blocking", t, func() {
testStarNonBlock(AddrTestTCP, tcp.NewTransport())
testStarNonBlock(AddrTestTCP(), tcp.NewTransport())
})
}
2 changes: 1 addition & 1 deletion test/survnonblock_test.go
Expand Up @@ -60,6 +60,6 @@ func testSurvNonBlock(addr string, tran mangos.Transport) {

func TestSurveyorNonBlockTCP(t *testing.T) {
Convey("Testing Survey Send (TCP) is Non-Blocking", t, func() {
testSurvNonBlock(AddrTestTCP, tcp.NewTransport())
testSurvNonBlock(AddrTestTCP(), tcp.NewTransport())
})
}
5 changes: 3 additions & 2 deletions test/ttl_test.go
Expand Up @@ -130,6 +130,7 @@ func TTLDropTest(t *testing.T, cli newSockFunc, srv newSockFunc) {
clis := make([]mangos.Socket, 0, nhop)
srvs := make([]mangos.Socket, 0, nhop)
inp := inproc.NewTransport()
a := AddrTestInp()

for i := 0; i < nhop; i++ {
s, err := srv()
Expand All @@ -141,7 +142,7 @@ func TTLDropTest(t *testing.T, cli newSockFunc, srv newSockFunc) {

s.AddTransport(inp)

err = s.Listen(AddrTestInp + fmt.Sprintf("HOP%d", i))
err = s.Listen(a + fmt.Sprintf("HOP%d", i))
if err != nil {
t.Errorf("Failed listen: %v", err)
return
Expand All @@ -166,7 +167,7 @@ func TTLDropTest(t *testing.T, cli newSockFunc, srv newSockFunc) {

s.AddTransport(inp)

err = s.Dial(AddrTestInp + fmt.Sprintf("HOP%d", i))
err = s.Dial(a + fmt.Sprintf("HOP%d", i))
if err != nil {
t.Errorf("Failed dial: %v", err)
return
Expand Down

0 comments on commit 52bc424

Please sign in to comment.