From 35f8d09c79361c4367dada1fa1de0d1ab0704819 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Sat, 8 Jun 2024 06:14:08 +0930 Subject: [PATCH] packetbeat/route: fix test failure on Windows 2022 (#39822) Windows 2022 appears to have added new text to the output of netsh. The text is interpreted as having three fields. This impact on the behaviour of the field splitting which expects five. - Originally this would cause a panic due to bounds checking. This was fixed in #39757 by erroring on an unexpectedly short line. - The fieldsN helper expects lines to be n fields or longer, but does not terminate on lines with fewer fields. So treat the first blank line found in the table as the end of the table and fix the fieldsN helper. --- CHANGELOG-developer.next.asciidoc | 1 + packetbeat/route/route_test.go | 1 - packetbeat/route/route_windows_test.go | 9 ++++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-developer.next.asciidoc b/CHANGELOG-developer.next.asciidoc index 15d65cf131b..58f9cea5211 100644 --- a/CHANGELOG-developer.next.asciidoc +++ b/CHANGELOG-developer.next.asciidoc @@ -98,6 +98,7 @@ The list below covers the major changes between 7.0.0-rc2 and main only. - Fix copy arguments for strict aligned architectures. {pull}36976[36976] - Fix panic when more than 32767 pipeline clients are active. {issue}38197[38197] {pull}38556[38556] - Skip flakey metrics test on windows in filebeat httpjson input. {issue}39676[39676] {pull}39678[39678] +- Fix flakey test on Windows 2022 in packetbeat/route. {issue}39698[39698] {pull}39822[39822] ==== Added diff --git a/packetbeat/route/route_test.go b/packetbeat/route/route_test.go index 2858d8521da..3e848bb56ab 100644 --- a/packetbeat/route/route_test.go +++ b/packetbeat/route/route_test.go @@ -32,7 +32,6 @@ import ( ) func TestDefault(t *testing.T) { - t.Skip("Flaky test: https://github.com/elastic/beats/issues/39698") for _, family := range []int{syscall.AF_INET, syscall.AF_INET6} { wantIface, wantIndex, wantErr := defaultRoute(family) if wantErr != nil && wantErr != ErrNotFound { diff --git a/packetbeat/route/route_windows_test.go b/packetbeat/route/route_windows_test.go index f216dabc338..1b513125f2d 100644 --- a/packetbeat/route/route_windows_test.go +++ b/packetbeat/route/route_windows_test.go @@ -54,6 +54,9 @@ func defaultRoute(af int) (name string, index int, err error) { for inTable := false; sc.Scan(); { f := strings.Fields(sc.Text()) if len(f) == 0 { + if inTable { + break + } continue } if !inTable { @@ -94,6 +97,9 @@ func defaultRoute(af int) (name string, index int, err error) { for inTable := false; sc.Scan(); { f := fieldsN(sc.Text(), 5) if len(f) == 0 { + if inTable { + break + } continue } if !inTable { @@ -152,6 +158,7 @@ func fieldsN(s string, n int) []string { } var f []string for s != "" { + l := len(s) for i, r := range s { if unicode.IsSpace(r) { f = append(f, s[:i]) @@ -165,7 +172,7 @@ func fieldsN(s string, n int) []string { break } } - if len(f) == n-1 { + if len(f) == n-1 || len(s) == l { break } }