Improve Add source/test reliability.

This commit is contained in:
Jay
2026-04-15 13:56:58 -04:00
parent d002c19889
commit be77bc53d0
2 changed files with 12 additions and 7 deletions
+4
View File
@@ -113,6 +113,10 @@ func (p *Pool) Add(rawURL string) error {
// Check for existing connection in pool
p.mu.Lock()
if p.closed {
p.mu.Unlock()
return errors.NewPoolError("pool is closed")
}
_, exists := p.connections[url]
p.mu.Unlock()
+8 -7
View File
@@ -25,13 +25,14 @@ func TestPoolAdd(t *testing.T) {
err = pool.Add("wss://test")
assert.NoError(t, err)
select {
case event := <-pool.events:
assert.Equal(t, "wss://test", event.URL)
assert.Equal(t, EventConnected, event.Kind)
case <-time.After(100 * time.Millisecond):
t.Fatal("timeout waiting for Connected event")
}
assert.Eventually(t, func() bool {
select {
case event := <-pool.events:
return event.URL == "wss://test" && event.Kind == EventConnected
default:
return false
}
}, testTimeout, testTick)
pool.Close()
})