diff options
author | Filippo Valsorda <hi@filippo.io> | 2018-05-20 23:12:55 -0400 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-21 20:20:13 +0200 |
commit | 7bdc5eb54ed7ac45016e6e028913f1594471a074 (patch) | |
tree | b53aaf5d0bb00cf84c6ea65e72510298c760c7f2 /helper_test.go | |
parent | 1c666576d584fd827dfcefdbabe797f391487624 (diff) |
Properly close DummyTUN to avoid deadlock in TestNoiseHandshake
License: MIT
Signed-off-by: Filippo Valsorda <valsorda@google.com>
Diffstat (limited to 'helper_test.go')
-rw-r--r-- | helper_test.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/helper_test.go b/helper_test.go index c72e868..b7c9c6c 100644 --- a/helper_test.go +++ b/helper_test.go @@ -8,6 +8,7 @@ package main import ( "bytes" + "errors" "os" "testing" ) @@ -40,6 +41,8 @@ func (tun *DummyTUN) Write(d []byte, offset int) (int, error) { } func (tun *DummyTUN) Close() error { + close(tun.events) + close(tun.packets) return nil } @@ -48,7 +51,10 @@ func (tun *DummyTUN) Events() chan TUNEvent { } func (tun *DummyTUN) Read(d []byte, offset int) (int, error) { - t := <-tun.packets + t, ok := <-tun.packets + if !ok { + return 0, errors.New("device closed") + } copy(d[offset:], t) return len(t), nil } @@ -57,6 +63,7 @@ func CreateDummyTUN(name string) (TUNDevice, error) { var dummy DummyTUN dummy.mtu = 0 dummy.packets = make(chan []byte, 100) + dummy.events = make(chan TUNEvent, 10) return &dummy, nil } |