mirror of
https://github.com/fumiama/water.git
synced 2026-06-28 07:50:25 +08:00
use blocking mode pre-go1.11
This commit is contained in:
29
ipv4_test.go
29
ipv4_test.go
@@ -1,9 +1,7 @@
|
||||
package water
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
const BUFFERSIZE = 1522
|
||||
@@ -22,30 +20,3 @@ func startRead(t *testing.T, ifce *Interface, dataCh chan<- []byte, errCh chan<-
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func TestCloseUnblockPendingRead(t *testing.T) {
|
||||
ifce, err := New(Config{DeviceType: TUN})
|
||||
if err != nil {
|
||||
t.Fatalf("creating TUN error: %v\n", err)
|
||||
}
|
||||
|
||||
c := make(chan struct{})
|
||||
go func() {
|
||||
ifce.Read(make([]byte, 1<<16))
|
||||
close(c)
|
||||
}()
|
||||
|
||||
// make sure ifce.Close() happens after ifce.Read() blocks
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
ifce.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
|
||||
select {
|
||||
case <-c:
|
||||
t.Log("Pending Read unblocked")
|
||||
case <-ctx.Done():
|
||||
t.Fatal("Timeouted, pending read blocked")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user