Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Jul 23, 2024
1 parent abba4cf commit af87dc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/heartbeat/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func RateLimited(offline paramscmd.Offline) bool {
return false
}

return time.Since(offline.LastSentAt) > offline.RateLimit
return time.Since(offline.LastSentAt) < offline.RateLimit
}

// ResetRateLimit updates the internal.heartbeats_last_sent_at timestamp

Check failure on line 203 in cmd/heartbeat/heartbeat.go

View workflow job for this annotation

GitHub Actions / Unit Tests

Comment should end in a period (godot)

Check failure on line 203 in cmd/heartbeat/heartbeat.go

View workflow job for this annotation

GitHub Actions / Unit Tests Windows

Comment should end in a period (godot)

Check failure on line 203 in cmd/heartbeat/heartbeat.go

View workflow job for this annotation

GitHub Actions / Unit Tests macOS

Comment should end in a period (godot)
Expand Down
10 changes: 8 additions & 2 deletions cmd/heartbeat/heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,14 @@ func TestSendHeartbeats_ObfuscateProjectNotBranch(t *testing.T) {
func TestRateLimited(t *testing.T) {
assert.False(t, cmdheartbeat.RateLimited(params.Offline{Disabled: true, RateLimit: 1, LastSentAt: time.Now()}))
assert.False(t, cmdheartbeat.RateLimited(params.Offline{RateLimit: 0, LastSentAt: time.Now()}))
assert.False(t, cmdheartbeat.RateLimited(params.Offline{RateLimit: offline.RateLimitDefaultSeconds, LastSentAt: time.Now().Add(time.Duration(-offline.RateLimitDefaultSeconds) * time.Second)}))
assert.True(t, cmdheartbeat.RateLimited(params.Offline{RateLimit: offline.RateLimitDefaultSeconds, LastSentAt: time.Now()}))

limit := time.Duration(offline.RateLimitDefaultSeconds) * time.Second

assert.False(t, cmdheartbeat.RateLimited(params.Offline{
RateLimit: limit,
LastSentAt: time.Now().Add(time.Duration(-offline.RateLimitDefaultSeconds*2) * time.Second),
}))
assert.True(t, cmdheartbeat.RateLimited(params.Offline{RateLimit: limit, LastSentAt: time.Now()}))
}

func setupTestServer() (string, *http.ServeMux, func()) {
Expand Down

0 comments on commit af87dc7

Please sign in to comment.