Skip to content

Commit

Permalink
drop sleeper
Browse files Browse the repository at this point in the history
  • Loading branch information
pznamensky authored and iainlane committed Aug 30, 2024
1 parent b9a3638 commit 8d84a87
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 20 deletions.
19 changes: 1 addition & 18 deletions internal/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,8 @@ type AuthInfo struct {
GithubToken string
}

// sleeper is a type that can sleep for a duration. It's used to allow for
// mocking sleep in tests. By default, it uses `time.Sleep`, but it can be
// initialised with a custom sleep function which will be called if set.
type sleeper struct {
doSleep func(time.Duration)
}

func (s *sleeper) sleep(d time.Duration) {
if s != nil {
s.doSleep(d)
return
}

time.Sleep(d)
}

type GHClient struct {
client *github.Client
sleeper *sleeper
pendingRecheckTime time.Duration
}

Expand Down Expand Up @@ -210,7 +193,7 @@ func (c GHClient) GetCIStatus(ctx context.Context, owner, repoName string, ref s
// and then check again.
if len(status.Statuses) == 0 {
log.Infof("No statuses found, waiting %s to see if one appears", c.pendingRecheckTime)
c.sleeper.sleep(c.pendingRecheckTime)
time.Sleep(c.pendingRecheckTime)

status, _, err = c.client.Repositories.GetCombinedStatus(ctx, owner, repoName, ref, nil)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions internal/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ func newClientFromMock(t *testing.T, mockClient *http.Client) *GHClient {

return &GHClient{
client: github.NewClient(httpClient),
sleeper: &sleeper{func(_ time.Duration) {}},
pendingRecheckTime: 1 * time.Second,
pendingRecheckTime: 0 * time.Second,
}
}

Expand Down

0 comments on commit 8d84a87

Please sign in to comment.