You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[8.19](backport #47969) fbreceiver: refactor receiver tests for maintainability (#47994)
* fbreceiver: refactor receiver tests for maintainability (#47969)
## Proposed commit message
Changes:
- Refactor TestMultipleReceivers to easily scale to n>2 receivers
- Clean up *.sock files
- Add multiReceiverHelper struct to encapsulate receiver test setup
- Add helper functions: hostFromSocket, writeFile
- Use UUID for socket path generation instead of random bytes
- Use DialContext instead of Dial to fix noctx lint warning
Pulled out from #47870 for easier review.
(cherry picked from commit 135d04f)
# Conflicts:
# x-pack/filebeat/fbreceiver/receiver_test.go
* Fix conflicts
* fbreceiver: close file in writeFile to fix Windows test (#48019)
On Windows, open file handles prevent t.TempDir() cleanup.
Add defer f.Close() to properly release the file handle.
Fixes test failure introduced in #47969.
---------
Co-authored-by: Orestis Floros <[email protected]>
require.Greater(c, len(logs["r1"]), 0, "receiver r1 does not have any logs")
247
-
require.Greater(c, len(logs["r2"]), 0, "receiver r2 does not have any logs")
248
-
249
-
assert.Equal(c, "filebeatreceiver/r1", logs["r1"][0].Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in r1 log record")
250
-
assert.Equal(c, "receiver", logs["r1"][0].Flatten()["agent.otelcol.component.kind"], "expected agent.otelcol.component.kind field in r1 log record")
251
-
assert.Equal(c, "filebeatreceiver/r2", logs["r2"][0].Flatten()["agent.otelcol.component.id"], "expected agent.otelcol.component.id field in r2 log record")
252
-
assert.Equal(c, "receiver", logs["r2"][0].Flatten()["agent.otelcol.component.kind"], "expected agent.otelcol.component.kind field in r2 log record")
253
-
254
-
// Make sure that each receiver has a separate logger
255
-
// instance and does not interfere with others. Previously, the
256
-
// logger in Beats was global, causing logger fields to be
257
-
// overwritten when multiple receivers started in the same process.
require.FileExists(c, reg1Path, "receiver 1 filebeat registry should exist")
296
-
reg1Data, err:=os.ReadFile(reg1Path)
297
-
require.NoError(c, err)
298
-
require.Containsf(c, string(reg1Data), string(ingest1Json), "receiver 1 registry should contain '%s', but was: %s", string(ingest1Json), string(reg1Data))
299
-
require.NotContainsf(c, string(reg1Data), string(ingest2Json), "receiver 1 registry should not contain '%s', but was: %s", string(ingest2Json), string(reg1Data))
require.FileExists(c, reg2Path, "receiver 2 filebeat registry should exist")
303
-
reg2Data, err:=os.ReadFile(reg2Path)
304
-
require.NoError(c, err)
305
-
require.Containsf(c, string(reg2Data), string(ingest2Json), "receiver 2 registry should contain '%s', but was: %s", string(ingest2Json), string(reg2Data))
306
-
require.NotContainsf(c, string(reg2Data), string(ingest1Json), "receiver 2 registry should not contain '%s', but was: %s", string(ingest1Json), string(reg2Data))
276
+
fori:=rangenReceivers {
277
+
forj:=rangenReceivers {
278
+
ifi==j {
279
+
continue
280
+
}
281
+
h1:=helpers[i]
282
+
h2:=helpers[j]
283
+
assert.NotEqualf(c, allMetaData[i], allMetaData[j], "meta data files between %v and %v should be different", h1, h2)
284
+
assert.NotContainsf(c, allRegData[i], allRegData[j], "receiver %v registry should not contain data from %v registry", h1, h2)
0 commit comments