Skip to content

Commit

Permalink
fix intermittent locking test
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRichardson committed Mar 19, 2024
1 parent 52ca10a commit edeb2d4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/objectstore/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ func (s *baseObjectStoreSuite) TestLocking(c *gc.C) {

s.expectClaimRelease("hash")
s.expectExtendDuration(time.Second)
s.expectClockAfter(make(chan time.Time))

// The clock after might not be called, as we might schedule the goroutine
// fast enough, that the second goroutine isn't called.
s.maybeExpectClockAfter(make(chan time.Time))

w := &baseObjectStore{
claimer: s.claimer,
Expand Down Expand Up @@ -335,6 +338,12 @@ func (s *baseObjectStoreSuite) setupMocks(c *gc.C) *gomock.Controller {
return ctrl
}

func (s *baseObjectStoreSuite) maybeExpectClockAfter(ch chan time.Time) {
s.clock.EXPECT().After(gomock.Any()).DoAndReturn(func(dur time.Duration) <-chan time.Time {
return ch
}).AnyTimes()
}

func (s *baseObjectStoreSuite) expectClockAfter(ch chan time.Time) {
s.clock.EXPECT().After(gomock.Any()).DoAndReturn(func(dur time.Duration) <-chan time.Time {
return ch
Expand Down

0 comments on commit edeb2d4

Please sign in to comment.