Skip to content

CBG-5969: fix staticcheck single-case select warnings - #8519

Open
torcolvin wants to merge 4 commits into
mainfrom
CBG-5969-gopls-channel
Open

CBG-5969: fix staticcheck single-case select warnings#8519
torcolvin wants to merge 4 commits into
mainfrom
CBG-5969-gopls-channel

Conversation

@torcolvin

@torcolvin torcolvin commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

CBG-5969: fix staticcheck single-case select warnings

silences warnings for gopls especially.

Integration Tests

- Enable staticcheck rule S1000 in .golangci-strict.yml

- Replace single-case select inside db/change_cache_test.go with a simple channel receive

- Remove redundant loop and select on ticker.C in tools/cache_perf_tool/main.go
@torcolvin
torcolvin requested a review from bbrks July 31, 2026 15:26
Copilot AI review requested due to automatic review settings July 31, 2026 15:26
@factory-droid

factory-droid Bot commented Jul 31, 2026

Copy link
Copy Markdown

Droid finished @torcolvin's task —— View job


Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses staticcheck S1000 (“single-case select”) warnings by simplifying channel/ticker waits to direct receives, and updates the strict golangci-lint configuration accordingly.

Changes:

  • Replace single-case select blocks with direct channel receives in a tool and a unit test.
  • Remove the .golangci-strict.yml exemption for S1000 so future violations are flagged.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tools/cache_perf_tool/main.go Simplifies the test-duration wait logic (removes single-case select).
db/change_cache_test.go Simplifies feed consumption loop (removes single-case select).
.golangci-strict.yml Re-enables staticcheck rule S1000 enforcement.

Comment thread tools/cache_perf_tool/main.go Outdated
Comment on lines +225 to +229
ticker := time.NewTicker(*timeToRun)
defer ticker.Stop()

outerloop:
for {
select {
case <-ticker.C:
cancelFunc(errors.New("test duration complete"))
break outerloop
}
}
<-ticker.C
cancelFunc(errors.New("test duration complete"))
Comment thread db/change_cache_test.go Outdated
Comment on lines +1071 to +1075
go func() {
for feedClosed == false {
select {
case entry, ok := <-feed:
if ok {
// feed sends nil after each continuous iteration
if entry != nil {
log.Println("Changes entry:", entry.Seq)
changes.lock.Lock()
changes.entries = append(changes.entries, entry)
changes.lock.Unlock()
}
} else {
log.Println("Closing feed")
feedClosed = true
entry, ok := <-feed
if ok {
// feed sends nil after each continuous iteration

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 if we weren't changing much here - but this whole test is a bit weirdly structured and seems overly reliant on timing/sleeps? I'm not sure how this is not flaky.

I think this actually warrants a rewrite using synctest to simulate the time and probably a waitgroup goroutine to drain the feed?

@factory-droid factory-droid Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated the candidate set: there were no inline comment candidates to review for this PR. The diff appears to be a behavior-preserving change to satisfy staticcheck S1000 by removing single-case selects.

@bbrks bbrks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I very much dislike these two areas of code already - what do we want to do about them? The changes to satisfy the linter don't go far enough IMO

Comment thread tools/cache_perf_tool/main.go Outdated
Comment on lines +224 to +228
@@ -225,14 +225,8 @@ func main() {
ticker := time.NewTicker(*timeToRun)
defer ticker.Stop()

outerloop:
for {
select {
case <-ticker.C:
cancelFunc(errors.New("test duration complete"))
break outerloop
}
}
<-ticker.C

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not just a time.Sleep()?

Comment thread db/change_cache_test.go Outdated
Comment on lines +1071 to +1075
go func() {
for feedClosed == false {
select {
case entry, ok := <-feed:
if ok {
// feed sends nil after each continuous iteration
if entry != nil {
log.Println("Changes entry:", entry.Seq)
changes.lock.Lock()
changes.entries = append(changes.entries, entry)
changes.lock.Unlock()
}
} else {
log.Println("Closing feed")
feedClosed = true
entry, ok := <-feed
if ok {
// feed sends nil after each continuous iteration

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 if we weren't changing much here - but this whole test is a bit weirdly structured and seems overly reliant on timing/sleeps? I'm not sure how this is not flaky.

I think this actually warrants a rewrite using synctest to simulate the time and probably a waitgroup goroutine to drain the feed?

@bbrks bbrks assigned torcolvin and unassigned bbrks Jul 31, 2026
torcolvin and others added 3 commits August 4, 2026 14:42
- tools/cache_perf_tool/main.go: replace the one-shot ticker+receive with
  time.Sleep, since only a single wake-up is needed.
- db/change_cache_test.go TestChannelRace: drop the redundant feedClosed
  flag in favor of ranging over the feed channel, and replace the fixed
  time.Sleep-then-assert waits (which didn't allow for slow processing)
  with require.EventuallyWithT polling. The mid-test sleeps that
  deliberately land within a specific cache-processing race window are
  left as-is, since they encode the scenario under test.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Replace timing-dependent sleeps with a LeakyBucket write callback that
reliably delays sequence 6's visibility, and drop the background drain
goroutine/polling for a simple synchronous drainFeed helper. Update the
expected sequences to match the real compound-ID backfill behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@torcolvin
torcolvin requested a review from a team August 5, 2026 14:01
@torcolvin torcolvin assigned bbrks and unassigned torcolvin Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants