Skip to content

Commit

Permalink
Merge pull request juju#17052 from SimonRichardson/objectstore-failure
Browse files Browse the repository at this point in the history
juju#17052

Fixes intermittent failure within the objectstore S3 tests. The changes move the internal state call until we've started up the object store. Otherwise, there is a race between the test code and the implementation around what gets called or not.

<!-- Why this change is needed and what it does. -->

## Checklist

- [x] Code style: imports ordered, good names, simple structure, etc

## QA steps

```sh
$ go test -v ./internal/objectstore -check.v -count=10
```
  • Loading branch information
jujubot authored Mar 19, 2024
2 parents bd28fc3 + edeb2d4 commit 6b8930d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
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
6 changes: 3 additions & 3 deletions internal/objectstore/s3objectstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,6 @@ func (t *s3ObjectStore) Remove(ctx context.Context, path string) error {
}

func (t *s3ObjectStore) loop() error {
// Report the initial started state.
t.reportInternalState(stateStarted)

// Ensure the namespace directory exists, along with the tmp directory.
if err := t.ensureDirectories(); err != nil {
return errors.Annotatef(err, "ensuring file store directories exist")
Expand Down Expand Up @@ -327,6 +324,9 @@ func (t *s3ObjectStore) loop() error {
fileFallback = useFileAccessor
}

// Report the initial started state.
t.reportInternalState(stateStarted)

// Sequence the get request with the put, remove requests.
for {
select {
Expand Down

0 comments on commit 6b8930d

Please sign in to comment.