From 65ebdfb8af80289356ff33e0c53e1fc3ee434182 Mon Sep 17 00:00:00 2001 From: Keegan Carruthers-Smith Date: Tue, 9 Apr 2024 17:50:30 +0200 Subject: [PATCH] schema: remove non-determinism from TestSchemaValidationUUID (#61728) Noticed this test failing once locally and worked out the source of the flakiness. Could reproduce with the below test plan. Test Plan: "go test -race -count=100 ./schema" passes --- schema/validation_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/schema/validation_test.go b/schema/validation_test.go index d291106ee19..e861d6dec78 100644 --- a/schema/validation_test.go +++ b/schema/validation_test.go @@ -1,6 +1,7 @@ package schema import ( + "sort" "strings" "testing" @@ -67,7 +68,15 @@ func TestSchemaValidationUUID(t *testing.T) { * uuid-escaped: Does not match pattern '^\{[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}\}$' * uuid-unescaped: Does not match pattern '^\{[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\}$'` - if diff := cmp.Diff(err.Error(), wantErr); diff != "" { + // order of errors is not deterministic due to internal use of go + // maps. + sortedLines := func(s string) string { + lines := strings.Split(s, "\n") + sort.Strings(lines) + return strings.Join(lines, "\n") + } + + if diff := cmp.Diff(sortedLines(err.Error()), sortedLines(wantErr)); diff != "" { t.Fatalf("wrong error message: %s", diff) } })