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