Skip to content

Commit

Permalink
Merge pull request #974 from wakatime/develop
Browse files Browse the repository at this point in the history
Release v1.86.5
  • Loading branch information
alanhamlett authored Oct 27, 2023
2 parents 6c9f891 + 93c7e6b commit 545165f
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 16 deletions.
20 changes: 13 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,27 @@ Tip: run `ln -sf $(pwd)/build/* ~/.wakatime/` to have the plugins use your local

## Branches

This project currently has two branches
PR branch names must use one of the following prefixes:

- `develop` - Default branch for every new `feature` or `fix`
- `release` - Branch for production releases and hotfixes
- `^major/.+` - `major`
- `^feature/.+` - `minor`
- `^bugfix/.+` - `patch`
- `^docs?/.+` - `build`
- `^misc/.+` - `build`

This branching strategy comes from [semver-action](https://github.com/wakatime/semver-action#branch-names).

We use two branches:

- `develop` - Default branch. PRs are merged to this branch.
- `release` - Branch for production releases and hotfixes. GitHub Actions automatically builds releases from this branch.

## Testing and Linting

Run `make test-all` before creating any pull requests, or your PR won’t pass the automated checks.

> make sure you build binary by setting its version otherwise integration tests will fail. `VERSION=v0.0.1-test make build-<os>-<architecture>`. For testing shell scripts you might initialize submodules by running `git submodule update --init --recursive`.
## Branching Stratgegy

Please follow our guideline for branch names [here](https://github.com/wakatime/semver-action#branch-names). Branches off the pattern won't be accepted.

## Pull Requests

- Big changes, changes to the API, or changes with backward compatibility trade-offs should be first discussed in the Slack.
Expand Down
2 changes: 2 additions & 0 deletions TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Set `debug=true` in your `~/.wakatime.cfg` file to enable verbose logging.

The common wakatime-cli program logs to your user `$HOME` directory `~/.wakatime/wakatime.log`.

If your error message contains `won't send heartbeat due to backoff`, delete your `~/.wakatime/wakatime-internal.cfg` file to trigger an API connection to get the real error message.

Each plugin also has its own log file:

* **Atom** writes errors to the developer console (View -> Developer -> Toggle Developer Tools)
Expand Down
2 changes: 1 addition & 1 deletion cmd/heartbeat/heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ func TestSendHeartbeats_ErrBackoff_Verbose(t *testing.T) {
output, err := io.ReadAll(logFile)
require.NoError(t, err)

assert.Contains(t, string(output), "will retry at")
assert.Contains(t, string(output), "will retry again after")
}

func TestSendHeartbeats_ObfuscateProject(t *testing.T) {
Expand Down
6 changes: 5 additions & 1 deletion pkg/backoff/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ func shouldBackoff(retries int, at time.Time) bool {
return false
}

if at.Add(duration).Before(time.Now()) {
return false
}

log.Debugf(
"exponential backoff tried %d times since %s, will retry at %s",
"exponential backoff tried %d times since %s, will retry again after %s",
retries,
at.Format(ini.DateFormat),
time.Now().Add(duration).Format(ini.DateFormat),
Expand Down
65 changes: 58 additions & 7 deletions pkg/backoff/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,6 @@ func TestWithBackoff_ApiError(t *testing.T) {

defer tmpFile.Close()

err = ini.ReadInConfig(v, tmpFile.Name())
require.NoError(t, err)

// make sure backoff settings start empty
assert.Empty(t, v.GetString("internal.backoff_at"))
assert.Empty(t, v.GetString("internal.backoff_retries"))

v.Set("internal-config", tmpFile.Name())

opt := backoff.WithBackoff(backoff.Config{
Expand Down Expand Up @@ -321,3 +314,61 @@ func TestWithBackoff_BackoffMaxReachedWithZeroRetries(t *testing.T) {
assert.Empty(t, v.GetString("internal.backoff_at"))
assert.Equal(t, "0", v.GetString("internal.backoff_retries"))
}

func TestWithBackoff_ShouldRetry(t *testing.T) {
v := viper.New()

tmpFile, err := os.CreateTemp(t.TempDir(), "wakatime")
require.NoError(t, err)

defer tmpFile.Close()

v.Set("internal-config", tmpFile.Name())

opt := backoff.WithBackoff(backoff.Config{
V: v,
})

handle := opt(func(hh []heartbeat.Heartbeat) ([]heartbeat.Result, error) {
return []heartbeat.Result{}, errors.New("error")
})

_, err = handle([]heartbeat.Heartbeat{})
require.Error(t, err)

assert.Equal(t, "error", err.Error())

err = ini.ReadInConfig(v, tmpFile.Name())
require.NoError(t, err)

// make sure backoff settings written
assert.NotEmpty(t, v.GetString("internal.backoff_at"))
assert.Equal(t, "1", v.GetString("internal.backoff_retries"))

at := time.Now()

// then, make sure we retry if after rate limit
opt = backoff.WithBackoff(backoff.Config{
V: v,
Retries: 1,
At: at.Add(time.Second * -60),
})

handle = opt(func(hh []heartbeat.Heartbeat) ([]heartbeat.Result, error) {
return []heartbeat.Result{
{
Status: 201,
},
}, nil
})

_, err = handle([]heartbeat.Heartbeat{})
require.NoError(t, err)

err = ini.ReadInConfig(v, tmpFile.Name())
require.NoError(t, err)

// make sure backoff settings reset
assert.Empty(t, v.GetString("internal.backoff_at"))
assert.Equal(t, "0", v.GetString("internal.backoff_retries"))
}

0 comments on commit 545165f

Please sign in to comment.