Skip to content

Commit f979ae2

Browse files
otel: enable TestReceiverDegraded and fix TestConsumeContract (#47753) (#47797)
Enable TestReceiverDegraded and TestConsumeContract that were skipped due to flakiness in the tests. TestConsumeContract needs the log generator to run in isolation, so provide a clean state when the generator starts. TestReceiverDegraded was only flaking on linux/arm64 and was fixed by #47573. (cherry picked from commit cdb243c) Co-authored-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
1 parent 5d2b97f commit f979ae2

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

x-pack/filebeat/fbreceiver/receiver_test.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,6 @@ func TestMultipleReceivers(t *testing.T) {
273273
}
274274

275275
func TestReceiverDegraded(t *testing.T) {
276-
if runtime.GOARCH == "arm64" && runtime.GOOS == "linux" {
277-
t.Skip("flaky test on Ubuntu arm64, see https://github.com/elastic/beats/issues/46437")
278-
}
279276
testCases := []struct {
280277
name string
281278
status oteltest.ExpectedStatus
@@ -440,26 +437,40 @@ type logGenerator struct {
440437
t *testing.T
441438
tmpDir string
442439
f *os.File
443-
filePattern string
444440
sequenceNum int64
441+
currentFile string
445442
}
446443

447444
func newLogGenerator(t *testing.T, tmpDir string) *logGenerator {
448445
return &logGenerator{
449-
t: t,
450-
tmpDir: tmpDir,
451-
filePattern: "input-*.log",
446+
t: t,
447+
tmpDir: tmpDir,
452448
}
453449
}
454450

455451
func (g *logGenerator) Start() {
456-
f, err := os.CreateTemp(g.tmpDir, g.filePattern)
452+
if g.currentFile != "" {
453+
os.Remove(g.currentFile)
454+
}
455+
456+
filePath := filepath.Join(g.tmpDir, "input.log")
457+
458+
f, err := os.Create(filePath)
457459
require.NoError(g.t, err)
458460
g.f = f
461+
g.currentFile = filePath
462+
atomic.StoreInt64(&g.sequenceNum, 0)
459463
}
460464

461465
func (g *logGenerator) Stop() {
462-
require.NoError(g.t, g.f.Close())
466+
if g.f != nil {
467+
require.NoError(g.t, g.f.Close())
468+
g.f = nil
469+
}
470+
if g.currentFile != "" {
471+
os.Remove(g.currentFile)
472+
g.currentFile = ""
473+
}
463474
}
464475

465476
func (g *logGenerator) Generate() []receivertest.UniqueIDAttrVal {
@@ -480,8 +491,6 @@ func (g *logGenerator) Generate() []receivertest.UniqueIDAttrVal {
480491
// - Random permanent error. We expect the batch to be dropped.
481492
// - Random error. We expect the batch to be retried or dropped based on the error type.
482493
func TestConsumeContract(t *testing.T) {
483-
t.Skip("flaky test, see https://github.com/elastic/beats/issues/46437")
484-
485494
defer oteltest.VerifyNoLeaks(t)
486495

487496
tmpDir := t.TempDir()
@@ -501,7 +510,7 @@ func TestConsumeContract(t *testing.T) {
501510
"id": "filestream-test",
502511
"enabled": true,
503512
"paths": []string{
504-
filepath.Join(tmpDir, "input-*.log"),
513+
filepath.Join(tmpDir, "input.log"),
505514
},
506515
"file_identity.native": map[string]any{},
507516
"prospector": map[string]any{

0 commit comments

Comments
 (0)