11package scheduler_test
22
33import (
4- "bytes"
54 "context"
65 "errors"
6+ "sync/atomic"
77 "testing"
88 "time"
99
@@ -14,45 +14,45 @@ import (
1414func TestSuccessRun (t * testing.T ) {
1515 t .Parallel ()
1616
17- buf := bytes. Buffer {}
17+ var counter atomic. Int32
1818 s := scheduler .New (1 * time .Second , application .RunnerFunc (func (ctx context.Context ) error {
19- buf . WriteString ( "1" )
19+ counter . Add ( 1 )
2020 return nil
2121 }))
2222
2323 go s .Run (context .TODO ())
2424
2525 time .Sleep (3500 * time .Millisecond )
2626
27- if buf . String () != "111" {
28- t .Errorf ("wrong buffer content . expected %v, got %v" , "111" , buf . String ())
27+ if counter . Load () != 3 {
28+ t .Errorf ("wrong counter value . expected %v, got %v" , 3 , counter . Load ())
2929 }
3030}
3131
3232func TestErrorRun (t * testing.T ) {
3333 t .Parallel ()
3434
35- buf := bytes. Buffer {}
35+ var counter atomic. Int32
3636 s := scheduler .New (1 * time .Second , application .RunnerFunc (func (ctx context.Context ) error {
37- buf . WriteString ( "1" )
37+ counter . Add ( 1 )
3838 return errors .New ("some error" )
3939 }))
4040
4141 go s .Run (context .TODO ())
4242
4343 time .Sleep (3500 * time .Millisecond )
4444
45- if buf . String () != "111" {
46- t .Errorf ("wrong buffer content . expected %v, got %v" , "111" , buf . String ())
45+ if counter . Load () != 3 {
46+ t .Errorf ("wrong counter value . expected %v, got %v" , 3 , counter . Load ())
4747 }
4848}
4949
5050func TestContextDecline (t * testing.T ) {
5151 t .Parallel ()
5252
53- buf := bytes. Buffer {}
53+ var counter atomic. Int32
5454 s := scheduler .New (1 * time .Second , application .RunnerFunc (func (ctx context.Context ) error {
55- buf . WriteString ( "1" )
55+ counter . Add ( 1 )
5656 return nil
5757 }))
5858
@@ -65,8 +65,8 @@ func TestContextDecline(t *testing.T) {
6565
6666 err := s .Run (ctx )
6767
68- if buf . String () != "111" {
69- t .Errorf ("wrong buffer content . expected %v, got %v" , "111" , buf . String ())
68+ if counter . Load () != 3 {
69+ t .Errorf ("wrong counter value . expected %v, got %v" , 3 , counter . Load ())
7070 }
7171
7272 if err == nil {
0 commit comments