Skip to content

Commit

Permalink
Wait for workers to stop in TestPostVerifierScaling (#5525)
Browse files Browse the repository at this point in the history
## Motivation

Unit test `TestPostVerifierScaling` is flaky because the test doesn't wait for the workers to stop after scaling the pool down.
  • Loading branch information
poszu committed Jan 31, 2024
1 parent 2e62c16 commit 9260b26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions activation/post_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type postVerifierWorker struct {
prioritized <-chan *verifyPostJob
jobs <-chan *verifyPostJob
stop chan struct{} // signal to stop this worker
stopped chan struct{} // signal that this worker has stopped
shutdown chan struct{} // signal that the verifier is closing
}

Expand Down Expand Up @@ -215,6 +216,7 @@ func (v *offloadingPostVerifier) scale(target int) {
prioritized: v.prioritized,
jobs: v.jobs,
stop: make(chan struct{}),
stopped: make(chan struct{}),
shutdown: v.stop,
}
v.workers = append(v.workers, w)
Expand All @@ -227,6 +229,9 @@ func (v *offloadingPostVerifier) scale(target int) {
for _, worker := range toStop {
close(worker.stop)
}
for _, worker := range toStop {
<-worker.stopped
}
}
}

Expand Down Expand Up @@ -293,6 +298,7 @@ func (v *offloadingPostVerifier) Close() error {
func (w *postVerifierWorker) start() {
w.log.Info("starting")
defer w.log.Info("stopped")
defer close(w.stopped)

for {
// First try to process a prioritized job.
Expand Down
1 change: 1 addition & 0 deletions activation/post_verifier_scaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func TestPostVerifierScaling(t *testing.T) {
require.NoError(t, err)

v.scale(0)

ctx, cancel = context.WithTimeout(context.Background(), 10*time.Millisecond)
defer cancel()
err = v.Verify(ctx, &shared.Proof{}, &shared.ProofMetadata{})
Expand Down

0 comments on commit 9260b26

Please sign in to comment.