Skip to content

Commit

Permalink
fixup! add new cache.Options field to customize transform
Browse files Browse the repository at this point in the history
attempt to fix race introduced in test by not referring to modified variable within callback
  • Loading branch information
alexzielenski committed Apr 14, 2022
1 parent 42167fb commit d451655
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,19 @@ var _ = Describe("Cache with transformers", func() {
})

BeforeEach(func() {
transformerHits = make(chan struct{}, 10)
hitsChan := make(chan struct{}, 10)

var err error
var transform = func(i interface{}) (interface{}, error) {
transformerHits <- struct{}{}
select {
case hitsChan <- struct{}{}:
// Notified the hit
default:
// don't block on sending
}
return i, nil
}
transformerHits = hitsChan

clien, err = client.New(cfg, client.Options{})
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -218,7 +224,6 @@ var _ = Describe("Cache with transformers", func() {
informerCacheCancel()

// Reset channel for future tests
close(transformerHits)
transformerHits = nil
})

Expand Down

0 comments on commit d451655

Please sign in to comment.