diff --git a/backend/cmd/multiplexer_test.go b/backend/cmd/multiplexer_test.go index 20160a7934..1044d9111e 100644 --- a/backend/cmd/multiplexer_test.go +++ b/backend/cmd/multiplexer_test.go @@ -200,6 +200,7 @@ func TestUpdateStatus(t *testing.T) { conn := &Connection{ Status: ConnectionStatus{}, Done: make(chan struct{}), + mu: sync.RWMutex{}, } // Test different state transitions @@ -211,7 +212,9 @@ func TestUpdateStatus(t *testing.T) { } for _, state := range states { + conn.mu.Lock() conn.Status.State = state + conn.mu.Unlock() assert.Equal(t, state, conn.Status.State) } @@ -222,15 +225,18 @@ func TestUpdateStatus(t *testing.T) { go func(i int) { defer wg.Done() - + conn.mu.Lock() state := states[i%len(states)] conn.Status.State = state + conn.mu.Unlock() }(i) } wg.Wait() // Verify final state is valid + conn.mu.RLock() assert.Contains(t, states, conn.Status.State) + conn.mu.RUnlock() } func TestMonitorConnection_Reconnect(t *testing.T) { diff --git a/backend/pkg/cache/cache.go b/backend/pkg/cache/cache.go index 6e2191b374..2e0c3dad0e 100644 --- a/backend/pkg/cache/cache.go +++ b/backend/pkg/cache/cache.go @@ -126,13 +126,13 @@ func (c *cache[T]) cleanUp() { for { <-ticker.C + c.lock.Lock() for key, value := range c.store { if !value.expiresAt.IsZero() && value.expiresAt.Before(time.Now()) { - c.lock.Lock() delete(c.store, key) - c.lock.Unlock() } } + c.lock.Unlock() } }