Skip to content

Commit

Permalink
fix: fix race in http sync test (#401)
Browse files Browse the repository at this point in the history
In the `TestSimpleSync` test we are asserting that `hs.Cron.AddFunc` and
`hs.Cron.Start` are called by the time the `dataSync` is sent. This is a
race, because these methods are actually called after the first send. I
get failures here ~25% of the time (seems like @skyerus does too).

This changes things to add the handler and start the cron _before_ the
first send, which makes things deterministic.

Signed-off-by: Todd Baert <toddbaert@gmail.com>
  • Loading branch information
toddbaert authored Feb 13, 2023
1 parent 9d7dbd1 commit 1d0c8e1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/sync/http/http_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ func (hs *Sync) Sync(ctx context.Context, dataSync chan<- sync.DataSync) error {
return err
}

dataSync <- sync.DataSync{FlagData: fetch, Source: hs.URI, Type: sync.ALL}

_ = hs.Cron.AddFunc("*/5 * * * *", func() {
body, err := hs.fetchBodyFromURL(ctx, hs.URI)
if err != nil {
Expand Down Expand Up @@ -82,6 +80,9 @@ func (hs *Sync) Sync(ctx context.Context, dataSync chan<- sync.DataSync) error {
})

hs.Cron.Start()

dataSync <- sync.DataSync{FlagData: fetch, Source: hs.URI, Type: sync.ALL}

<-ctx.Done()
hs.Cron.Stop()

Expand Down

1 comment on commit 1d0c8e1

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Go Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.30.

Benchmark suite Current: 1d0c8e1 Previous: 9d7dbd1 Ratio
BenchmarkResolveBooleanValue/test_targetingBoolFlag 16517 ns/op 4817 B/op 80 allocs/op 12303 ns/op 4817 B/op 80 allocs/op 1.34
BenchmarkResolveIntValue/test_targetingNumberFlag 15292 ns/op 4825 B/op 80 allocs/op 11388 ns/op 4825 B/op 80 allocs/op 1.34
BenchmarkResolveObjectValue/test_targetingObjectFlag 22370 ns/op 6106 B/op 104 allocs/op 15835 ns/op 6106 B/op 104 allocs/op 1.41

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.