Skip to content

Commit

Permalink
[chore][exporter/elasticsearch] Fix TestExporter_PushEvent flaky test (
Browse files Browse the repository at this point in the history
…open-telemetry#32917)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
Fix a flaky test from open-telemetry#31694 due to non-deterministic JSON key order.

**Link to tracking Issue:** Closes open-telemetry#32910
  • Loading branch information
carsonip authored May 7, 2024
1 parent bea2130 commit 7f2b1b4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions exporter/elasticsearchexporter/logs_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down

0 comments on commit 7f2b1b4

Please sign in to comment.