@@ -68,49 +68,42 @@ func (cr *CommandRunner) FireCommandsUntilStop(ctx context.Context) {
6868 return
6969 case <- ctx .Done ():
7070 return
71- default :
72- select {
73- case <- cr .stopCh :
74- return
75- case <- ctx .Done ():
76- return
77- case <- ticker .C :
78- poolSize := cr .client .PoolStats ().IdleConns
79- if poolSize == 0 {
80- poolSize = 1
81- }
82- wg := sync.WaitGroup {}
83- for i := 0 ; i < int (poolSize ); i ++ {
84- wg .Add (1 )
85- go func (i int ) {
86- defer wg .Done ()
87- key := fmt .Sprintf ("timeout-test-key-%d-%d" , counter , i )
88- value := fmt .Sprintf ("timeout-test-value-%d-%d" , counter , i )
89-
90- // Use a short timeout context for individual operations
91- opCtx , cancel := context .WithTimeout (ctx , 2 * time .Second )
92- err := cr .client .Set (opCtx , key , value , time .Minute ).Err ()
93- cancel ()
94-
95- cr .operationCount .Add (1 )
96- if err != nil {
97- fmt .Printf ("Error: %v\n " , err )
98- cr .errorCount .Add (1 )
99-
100- // Check if it's a timeout error
101- if isTimeoutError (err ) {
102- cr .timeoutErrors .Add (1 )
103- }
104-
105- cr .errorsMutex .Lock ()
106- cr .errors = append (cr .errors , err )
107- cr .errorsMutex .Unlock ()
71+ case <- ticker .C :
72+ poolSize := cr .client .PoolStats ().IdleConns
73+ if poolSize == 0 {
74+ poolSize = 1
75+ }
76+ wg := sync.WaitGroup {}
77+ for i := 0 ; i < int (poolSize ); i ++ {
78+ wg .Add (1 )
79+ go func (i int ) {
80+ defer wg .Done ()
81+ key := fmt .Sprintf ("timeout-test-key-%d-%d" , counter , i )
82+ value := fmt .Sprintf ("timeout-test-value-%d-%d" , counter , i )
83+
84+ // Use a short timeout context for individual operations
85+ opCtx , cancel := context .WithTimeout (ctx , 2 * time .Second )
86+ err := cr .client .Set (opCtx , key , value , time .Minute ).Err ()
87+ cancel ()
88+
89+ cr .operationCount .Add (1 )
90+ if err != nil {
91+ fmt .Printf ("Error: %v\n " , err )
92+ cr .errorCount .Add (1 )
93+
94+ // Check if it's a timeout error
95+ if isTimeoutError (err ) {
96+ cr .timeoutErrors .Add (1 )
10897 }
109- }(i )
110- }
111- wg .Wait ()
112- counter ++
98+
99+ cr .errorsMutex .Lock ()
100+ cr .errors = append (cr .errors , err )
101+ cr .errorsMutex .Unlock ()
102+ }
103+ }(i )
113104 }
105+ wg .Wait ()
106+ counter ++
114107 }
115108 }
116109}
0 commit comments