Skip to content

Commit

Permalink
[ASCII-2461] Fix flaky TestRunProviders (#31879)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgimalac authored Dec 11, 2024
1 parent c239913 commit 6d7ae5b
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions comp/core/flare/flare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ func TestFlareCreation(t *testing.T) {
}

func TestRunProviders(t *testing.T) {
var firstRan atomic.Bool
var secondRan atomic.Bool
firstStarted := make(chan struct{}, 1)
var secondDone atomic.Bool

fakeTagger := mockTagger.SetupFakeTagger(t)
Expand Down Expand Up @@ -105,7 +104,7 @@ func TestRunProviders(t *testing.T) {
fx.Provide(fx.Annotate(
func() *types.FlareFiller {
return types.NewFiller(func(_ types.FlareBuilder) error {
firstRan.Store(true)
firstStarted <- struct{}{}
return nil
})
},
Expand All @@ -114,7 +113,6 @@ func TestRunProviders(t *testing.T) {
fx.Provide(fx.Annotate(
func() *types.FlareFiller {
return types.NewFiller(func(_ types.FlareBuilder) error {
secondRan.Store(true)
time.Sleep(10 * time.Second)
secondDone.Store(true)
return nil
Expand All @@ -130,9 +128,13 @@ func TestRunProviders(t *testing.T) {
fb, err := helpers.NewFlareBuilder(false, flarebuilder.FlareArgs{})
require.NoError(t, err)

start := time.Now()
f.Comp.(*flare).runProviders(fb, cliProviderTimeout)
// ensure that providers are actually started
<-firstStarted
elapsed := time.Since(start)

require.True(t, firstRan.Load())
require.True(t, secondRan.Load())
require.False(t, secondDone.Load())
// ensure that we're not blocking for the slow provider
assert.Less(t, elapsed, 5*time.Second)
assert.False(t, secondDone.Load())
}

0 comments on commit 6d7ae5b

Please sign in to comment.