Skip to content

Commit

Permalink
backend: multiplexer_test: Fix data race
Browse files Browse the repository at this point in the history
The race detector spotted an issue in this test.

Signed-off-by: René Dudfield <[email protected]>
  • Loading branch information
illume committed Jan 8, 2025
1 parent 26acf0b commit 192faac
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion backend/cmd/multiplexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func TestUpdateStatus(t *testing.T) {
conn := &Connection{
Status: ConnectionStatus{},
Done: make(chan struct{}),
mu: sync.RWMutex{},
}

// Test different state transitions
Expand All @@ -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)
}

Expand All @@ -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) {
Expand Down

0 comments on commit 192faac

Please sign in to comment.