From 7f2b1b4f7538478ca66fea0a27c55c3fd9209ec4 Mon Sep 17 00:00:00 2001 From: Carson Ip Date: Tue, 7 May 2024 18:11:31 +0100 Subject: [PATCH] [chore][exporter/elasticsearch] Fix TestExporter_PushEvent flaky test (#32917) **Description:** Fix a flaky test from #31694 due to non-deterministic JSON key order. **Link to tracking Issue:** Closes #32910 --- exporter/elasticsearchexporter/logs_exporter_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/exporter/elasticsearchexporter/logs_exporter_test.go b/exporter/elasticsearchexporter/logs_exporter_test.go index fad60b7a28d5..60bc7d6ba719 100644 --- a/exporter/elasticsearchexporter/logs_exporter_test.go +++ b/exporter/elasticsearchexporter/logs_exporter_test.go @@ -173,9 +173,15 @@ func TestExporter_PushEvent(t *testing.T) { server := newESTestServer(t, func(docs []itemRequest) ([]itemResponse, error) { rec.Record(docs) - expected := `{"attrKey1":"abc","attrKey2":"def","application":"myapp","service":{"name":"myservice"},"error":{"stacktrace":"no no no no"},"agent":{"name":"otlp"},"@timestamp":"1970-01-01T00:00:00.000000000Z","message":"hello world"}` - actual := string(docs[0].Document) - assert.Equal(t, expected, actual) + var expectedDoc, actualDoc map[string]any + expected := []byte(`{"attrKey1":"abc","attrKey2":"def","application":"myapp","service":{"name":"myservice"},"error":{"stacktrace":"no no no no"},"agent":{"name":"otlp"},"@timestamp":"1970-01-01T00:00:00.000000000Z","message":"hello world"}`) + err := json.Unmarshal(expected, &expectedDoc) + require.NoError(t, err) + + actual := docs[0].Document + err = json.Unmarshal(actual, &actualDoc) + require.NoError(t, err) + assert.Equal(t, expectedDoc, actualDoc) return itemsAllOK(docs) })