Skip to content

Commit

Permalink
vsock: test dialing to non-existent listeners
Browse files Browse the repository at this point in the history
Fixes #47
Updates lxc/lxd#9894

Signed-off-by: Matt Layher <[email protected]>
  • Loading branch information
mdlayher committed Feb 11, 2022
1 parent 99a6dcc commit dd97990
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions integration_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bytes"
"fmt"
"io"
"math"
"net"
"os"
"regexp"
Expand Down Expand Up @@ -200,6 +201,29 @@ func TestIntegrationConnSyscallConn(t *testing.T) {
}
}

func TestIntegrationConnDialNoListener(t *testing.T) {
// Dial out to vsock listeners which do not exist, and expect an immediate
// error rather than hanging. This mostly relies on changes to the
// underlying socket library, but we test it anyway to lock things in.
//
// See: https://github.com/mdlayher/vsock/issues/47.
const max = math.MaxUint32
for _, port := range []uint32{max - 2, max - 1, max} {
_, got := vsock.Dial(vsock.Local, port, nil)

want := &net.OpError{
Op: "dial",
Net: "vsock",
Addr: &vsock.Addr{ContextID: vsock.Local, Port: port},
Err: os.NewSyscallError("connect", unix.ECONNRESET),
}

if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("unexpected error (-want +got):\n%s", diff)
}
}
}

func isBrokenPipe(err error) bool {
if err == nil {
return false
Expand Down

0 comments on commit dd97990

Please sign in to comment.