Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
set linger to 0 on OSX in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed May 19, 2022
1 parent 7b09f5f commit 510212c
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,40 @@ func init() {
}
}

func acceptOne(t *testing.T, listener manet.Listener) <-chan interface{} {
func setLingerZero(c manet.Conn) {
if runtime.GOOS == "darwin" {
c.(interface{ SetLinger(int) error }).SetLinger(0)
}
}

func acceptOne(t *testing.T, listener manet.Listener) <-chan manet.Conn {
t.Helper()
done := make(chan interface{}, 1)
done := make(chan manet.Conn, 1)
go func() {
defer close(done)
done <- nil
c, err := listener.Accept()
if err != nil {
t.Error(err)
return
}
c.Close()
setLingerZero(c)
done <- c
}()
<-done
return done
}

func dialOne(t *testing.T, tr *Transport, listener manet.Listener, expected ...int) int {
t.Helper()

done := acceptOne(t, listener)
connChan := acceptOne(t, listener)
c, err := tr.Dial(listener.Multiaddr())
if err != nil {
t.Fatal(err)
}
setLingerZero(c)
port := c.LocalAddr().(*net.TCPAddr).Port
<-done
serverConn := <-connChan
serverConn.Close()
c.Close()
if len(expected) == 0 {
return port
Expand Down Expand Up @@ -126,9 +133,6 @@ func TestTwoLocal(t *testing.T) {
}

func TestGlobalPreferenceV4(t *testing.T) {
if runtime.GOOS == "darwin" {
t.Skip("This test is failing on OSX: https://github.com/libp2p/go-reuseport-transport/issues/33")
}
if globalV4 == nil {
t.Skip("no global IPv4 addresses configured")
return
Expand All @@ -143,9 +147,6 @@ func TestGlobalPreferenceV4(t *testing.T) {
}

func TestGlobalPreferenceV6(t *testing.T) {
if runtime.GOOS == "darwin" {
t.Skip("This test is failing on OSX: https://github.com/libp2p/go-reuseport-transport/issues/33")
}
if globalV6 == nil {
t.Skip("no global IPv6 addresses configured")
return
Expand All @@ -157,9 +158,6 @@ func TestGlobalPreferenceV6(t *testing.T) {
}

func TestLoopbackPreference(t *testing.T) {
if runtime.GOOS == "darwin" {
t.Skip("This test is failing on OSX: https://github.com/libp2p/go-reuseport-transport/issues/33")
}
testPrefer(t, loopbackV4, loopbackV4, unspecV4)
testPrefer(t, loopbackV6, loopbackV6, unspecV6)
}
Expand Down Expand Up @@ -244,9 +242,6 @@ func testUseFirst(t *testing.T, listen, use, never ma.Multiaddr) {
}

func TestDuplicateGlobal(t *testing.T) {
if runtime.GOOS == "darwin" {
t.Skip("This test is failing on OSX: https://github.com/libp2p/go-reuseport-transport/issues/33")
}
if globalV4 == nil {
t.Skip("no globalV4 addresses configured")
return
Expand Down

0 comments on commit 510212c

Please sign in to comment.