Improve Add source/test reliability.

This commit is contained in:
Jay
2026-04-15 13:56:58 -04:00
parent 12b6ac1a62
commit 901654745f
2 changed files with 12 additions and 7 deletions

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()

View File

@@ -25,13 +25,14 @@ func TestPoolAdd(t *testing.T) {
err = pool.Add("wss://test")
assert.NoError(t, err)
assert.Eventually(t, func() bool {
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")
return event.URL == "wss://test" && event.Kind == EventConnected
default:
return false
}
}, testTimeout, testTick)
pool.Close()
})