From 26ee0e2abe2de4d17f5489434faa42dd526a1d78 Mon Sep 17 00:00:00 2001 From: wangling142 Date: Thu, 26 Dec 2024 20:37:40 +0800 Subject: [PATCH] 1. fix rule test failed when rule add slow. --- rule_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rule_test.go b/rule_test.go index 59edb405..4420e5b5 100644 --- a/rule_test.go +++ b/rule_test.go @@ -6,6 +6,7 @@ package netlink import ( "net" "testing" + "time" "golang.org/x/sys/unix" ) @@ -583,11 +584,18 @@ func runRuleListFiltered(t *testing.T, family int, srcNet, dstNet *net.IPNet) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { rule := tt.preRun() + wantRules, wantErr := tt.setupWant(rule) + rules, err := RuleListFiltered(family, tt.ruleFilter, tt.filterMask) + for i := 0; i < len(wantRules); i++ { + if len(wantRules) == len(rules) { + break + } + time.Sleep(1 * time.Second) // wait rule take effect + rules, err = RuleListFiltered(family, tt.ruleFilter, tt.filterMask) + } tt.postRun(rule) - wantRules, wantErr := tt.setupWant(rule) - if len(wantRules) != len(rules) { t.Errorf("Expected len: %d, got: %d", len(wantRules), len(rules)) } else {