Skip to content

Commit

Permalink
test: fix flaky test
Browse files Browse the repository at this point in the history
Added the `time.Sleep()` call to make sure the second event
is actually always sent as the second one.
  • Loading branch information
andrzej-stencel committed Jun 29, 2022
1 parent 115e3f8 commit 291ddf3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/receiver/rawk8seventsreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func TestNoStorage(t *testing.T) {
// Both events should be picked up by the receiver.
assert.Eventually(t, func() bool {
return assert.Equal(t, 2, logsSink.LogRecordCount())
}, time.Second, 100*time.Millisecond)
}, 30*time.Millisecond, 10*time.Millisecond)

// Shutdown the receiver.
assert.NoError(t, receiver.Shutdown(ctx))
Expand Down Expand Up @@ -372,7 +372,7 @@ func TestNoStorage(t *testing.T) {
// which means it should get all three events.
assert.Eventually(t, func() bool {
return assert.Equal(t, 3, logsSink.LogRecordCount())
}, time.Second, 100*time.Millisecond)
}, 30*time.Millisecond, 10*time.Millisecond)
}

func TestStorage(t *testing.T) {
Expand Down Expand Up @@ -408,6 +408,8 @@ func TestStorage(t *testing.T) {
host := storagetest.NewStorageHost(t, storageDir, "test")
assert.NoError(t, receiver.Start(ctx, host))

time.Sleep(10 * time.Millisecond)

// Create the second k8s event.
secondEvent := getEvent()
firstEvent.UID = types.UID("ec279341-e2d8-4b2a-b17d-6e0566481002")
Expand All @@ -417,7 +419,7 @@ func TestStorage(t *testing.T) {
// The last resource version processed should be saved in storage.
assert.Eventually(t, func() bool {
return assert.Equal(t, 2, logsSink.LogRecordCount())
}, 2*time.Second, 100*time.Millisecond)
}, 30*time.Millisecond, 10*time.Millisecond)

// Shutdown the receiver.
require.NoError(t, receiver.Shutdown(ctx))
Expand Down Expand Up @@ -447,7 +449,7 @@ func TestStorage(t *testing.T) {
// as it is the only one with newer resource version.
assert.Eventually(t, func() bool {
return assert.Equal(t, 1, logsSink.LogRecordCount())
}, 2*time.Second, 100*time.Millisecond)
}, 30*time.Millisecond, 10*time.Millisecond)
}

func getEvent() *corev1.Event {
Expand Down

0 comments on commit 291ddf3

Please sign in to comment.