mirror of https://github.com/portainer/portainer
fix(scheduler): fix a data race in a unit test BE-11084 (#12057)
parent
bedb7fb255
commit
03e8d05f18
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -70,12 +71,10 @@ func Test_JobShouldNotStop_UponError(t *testing.T) {
|
|||
s := NewScheduler(context.Background())
|
||||
defer s.Shutdown()
|
||||
|
||||
var acc int
|
||||
var acc atomic.Int64
|
||||
ch := make(chan struct{})
|
||||
s.StartJobEvery(jobInterval, func() error {
|
||||
acc++
|
||||
|
||||
if acc == 2 {
|
||||
if acc.Add(1) == 2 {
|
||||
close(ch)
|
||||
return NewPermanentError(fmt.Errorf("failed"))
|
||||
}
|
||||
|
@ -85,7 +84,7 @@ func Test_JobShouldNotStop_UponError(t *testing.T) {
|
|||
|
||||
<-time.After(3 * jobInterval)
|
||||
<-ch
|
||||
assert.Equal(t, 2, acc)
|
||||
assert.Equal(t, int64(2), acc.Load())
|
||||
}
|
||||
|
||||
func Test_CanTerminateAllJobs_ByShuttingDownScheduler(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue