github.com/vishvananda/netlink@v1.3.0/xfrm_monitor_linux_test.go (about) 1 package netlink 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/vishvananda/netlink/nl" 8 ) 9 10 func TestXfrmMonitorExpire(t *testing.T) { 11 if os.Getenv("CI") == "true" { 12 t.Skipf("Flaky in CI: Intermittently causes 10 minute timeout") 13 } 14 defer setUpNetlinkTest(t)() 15 16 ch := make(chan XfrmMsg) 17 done := make(chan struct{}) 18 defer close(done) 19 errChan := make(chan error) 20 if err := XfrmMonitor(ch, nil, errChan, nl.XFRM_MSG_EXPIRE); err != nil { 21 t.Fatal(err) 22 } 23 24 // Program state with limits 25 state := getBaseState() 26 state.Limits.TimeHard = 2 27 state.Limits.TimeSoft = 1 28 if err := XfrmStateAdd(state); err != nil { 29 t.Fatal(err) 30 } 31 32 hardFound := false 33 softFound := false 34 35 msg := (<-ch).(*XfrmMsgExpire) 36 if msg.XfrmState.Spi != state.Spi { 37 t.Fatal("Received unexpected msg, spi does not match") 38 } 39 hardFound = msg.Hard || hardFound 40 softFound = !msg.Hard || softFound 41 42 msg = (<-ch).(*XfrmMsgExpire) 43 if msg.XfrmState.Spi != state.Spi { 44 t.Fatal("Received unexpected msg, spi does not match") 45 } 46 hardFound = msg.Hard || hardFound 47 softFound = !msg.Hard || softFound 48 49 if !hardFound || !softFound { 50 t.Fatal("Missing expire msg: hard found:", hardFound, "soft found:", softFound) 51 } 52 }