Skip to content

Commit

Permalink
fix flaky assertion in TestExporterMetrics
Browse files Browse the repository at this point in the history
This assertion was done in a json string. Sometimes the order of fields in
the json string changes which causes failures in the test.
  • Loading branch information
mauri870 committed Oct 7, 2024
1 parent 6928f2b commit 49f7771
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions exporter/elasticsearchexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ func TestExporterMetrics(t *testing.T) {
rec.Record(docs)
return itemsAllOK(docs)
})
defer server.Close()

exporter := newTestMetricsExporter(t, server.URL, func(cfg *Config) {
cfg.Mapping.Mode = "ecs"
Expand Down
8 changes: 7 additions & 1 deletion exporter/elasticsearchexporter/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 49f7771

Please sign in to comment.