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