File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed
Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,7 @@ func TestUpdateStatus(t *testing.T) {
200200 conn := & Connection {
201201 Status : ConnectionStatus {},
202202 Done : make (chan struct {}),
203+ mu : sync.RWMutex {},
203204 }
204205
205206 // Test different state transitions
@@ -211,7 +212,9 @@ func TestUpdateStatus(t *testing.T) {
211212 }
212213
213214 for _ , state := range states {
215+ conn .mu .Lock ()
214216 conn .Status .State = state
217+ conn .mu .Unlock ()
215218 assert .Equal (t , state , conn .Status .State )
216219 }
217220
@@ -222,15 +225,18 @@ func TestUpdateStatus(t *testing.T) {
222225
223226 go func (i int ) {
224227 defer wg .Done ()
225-
228+ conn . mu . Lock ()
226229 state := states [i % len (states )]
227230 conn .Status .State = state
231+ conn .mu .Unlock ()
228232 }(i )
229233 }
230234 wg .Wait ()
231235
232236 // Verify final state is valid
237+ conn .mu .RLock ()
233238 assert .Contains (t , states , conn .Status .State )
239+ conn .mu .RUnlock ()
234240}
235241
236242func TestMonitorConnection_Reconnect (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -126,13 +126,13 @@ func (c *cache[T]) cleanUp() {
126126 for {
127127 <- ticker .C
128128
129+ c .lock .Lock ()
129130 for key , value := range c .store {
130131 if ! value .expiresAt .IsZero () && value .expiresAt .Before (time .Now ()) {
131- c .lock .Lock ()
132132 delete (c .store , key )
133- c .lock .Unlock ()
134133 }
135134 }
135+ c .lock .Unlock ()
136136 }
137137}
138138
You can’t perform that action at this time.
0 commit comments