forked from vishvananda/netlink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xfrm_monitor_test.go
55 lines (45 loc) · 1.19 KB
/
xfrm_monitor_test.go
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
55
//go:build linux
// +build linux
package netlink
import (
"os"
"testing"
"github.com/vishvananda/netlink/nl"
)
func TestXfrmMonitorExpire(t *testing.T) {
if os.Getenv("CI") == "true" {
t.Skipf("Flaky in CI: Intermittently causes 10 minute timeout")
}
defer setUpNetlinkTest(t)()
ch := make(chan XfrmMsg)
done := make(chan struct{})
defer close(done)
errChan := make(chan error)
if err := XfrmMonitor(ch, nil, errChan, nl.XFRM_MSG_EXPIRE); err != nil {
t.Fatal(err)
}
// Program state with limits
state := getBaseState()
state.Limits.TimeHard = 2
state.Limits.TimeSoft = 1
if err := XfrmStateAdd(state); err != nil {
t.Fatal(err)
}
hardFound := false
softFound := false
msg := (<-ch).(*XfrmMsgExpire)
if msg.XfrmState.Spi != state.Spi {
t.Fatal("Received unexpected msg, spi does not match")
}
hardFound = msg.Hard || hardFound
softFound = !msg.Hard || softFound
msg = (<-ch).(*XfrmMsgExpire)
if msg.XfrmState.Spi != state.Spi {
t.Fatal("Received unexpected msg, spi does not match")
}
hardFound = msg.Hard || hardFound
softFound = !msg.Hard || softFound
if !hardFound || !softFound {
t.Fatal("Missing expire msg: hard found:", hardFound, "soft found:", softFound)
}
}