From e3a32b58ab9b4212921a6ef678ce5f9f0b084ec3 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 7 Jun 2024 21:18:07 +0000 Subject: [PATCH] packetbeat/route: fix test failure on Windows 2022 (#39822) (#39833) 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. (cherry picked from commit 35f8d09c79361c4367dada1fa1de0d1ab0704819) Co-authored-by: Dan Kortschak --- 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 73b53e370dc..d6bacc653b9 100644 --- a/CHANGELOG-developer.next.asciidoc +++ b/CHANGELOG-developer.next.asciidoc @@ -97,6 +97,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 3968c187fc7..32dd4cf60d1 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 { @@ -91,6 +94,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 { @@ -149,6 +155,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]) @@ -162,7 +169,7 @@ func fieldsN(s string, n int) []string { break } } - if len(f) == n-1 { + if len(f) == n-1 || len(s) == l { break } }