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

set linger to 0 on OSX in tests #42

Merged
merged 1 commit into from
May 19, 2022
Merged
Changes from all commits
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
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