From 256e465bfe9260526f4474cc4467bc0327278fe7 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Wed, 9 Oct 2024 08:33:29 -0300 Subject: [PATCH] [chore][exporter/elasticsearch] fix flaky assertion in TestExporterMetrics (#35639) #### Description Sometimes the order of fields in the json strings change which causes failures in the test. --- exporter/elasticsearchexporter/utils_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/exporter/elasticsearchexporter/utils_test.go b/exporter/elasticsearchexporter/utils_test.go index 82fcc0e22cde..05e9d8576a57 100644 --- a/exporter/elasticsearchexporter/utils_test.go +++ b/exporter/elasticsearchexporter/utils_test.go @@ -48,7 +48,13 @@ func assertItemsEqual(t *testing.T, expected, actual []itemRequest, assertOrder copy(actualItems, actual) slices.SortFunc(actualItems, itemRequestsSortFunc) } - assert.Equal(t, expectedItems, actualItems) + + assert.Equal(t, len(expectedItems), len(actualItems), "want %d items, got %d", len(expectedItems), len(actualItems)) + for i, want := range expectedItems { + got := actualItems[i] + assert.JSONEq(t, string(want.Action), string(got.Action), "item %d action", i) + assert.JSONEq(t, string(want.Document), string(got.Document), "item %d document", i) + } } type itemResponse struct {