forked from pion/dtls
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_errno_test.go
More file actions
54 lines (40 loc) · 1.4 KB
/
errors_errno_test.go
File metadata and controls
54 lines (40 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
//go:build aix || darwin || dragonfly || freebsd || linux || nacl || nacljs || netbsd || openbsd || solaris || windows
// For systems having syscall.Errno.
// The build target must be same as errors_errno.go.
package dtls
import (
"net"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestErrorsTemporary(t *testing.T) {
// Allocate a UDP port no one is listening on.
addrListen, err := net.ResolveUDPAddr("udp", "localhost:0")
assert.NoError(t, err)
listener, err := net.ListenUDP("udp", addrListen)
assert.NoError(t, err)
raddr, ok := listener.LocalAddr().(*net.UDPAddr)
assert.True(t, ok)
assert.NoError(t, listener.Close())
// Server is not listening.
conn, errDial := net.DialUDP("udp", nil, raddr)
assert.NoError(t, errDial)
_, _ = conn.Write([]byte{0x00}) // trigger
// Avoid indefinite blocking on platforms that don't surface ICMP errors reliably - Windows :)
_ = conn.SetReadDeadline(time.Now().Add(5 * time.Second))
_, err = conn.Read(make([]byte, 10))
_ = conn.Close()
if err == nil {
t.Skip("ECONNREFUSED is not set by system")
}
var ne net.Error
assert.ErrorAs(t, netError(err), &ne)
if ne.Timeout() {
t.Skip("timed out waiting for ICMP error; skipping on this platform")
}
assert.False(t, ne.Timeout())
assert.True(t, ne.Temporary()) //nolint:staticcheck
}