Add slog attributes at pool, worker, and connection levels.

This commit is contained in:
Jay
2026-04-23 17:58:40 -04:00
parent 91717457dd
commit 727dc18b57
17 changed files with 488 additions and 248 deletions
+9 -4
View File
@@ -15,7 +15,7 @@ import (
func setupPool(t *testing.T) (*Pool, *honeybeetest.MockDialer) {
t.Helper()
pool, err := NewPool(context.Background(), nil, nil)
pool, err := NewPool(context.Background(), "pool-1", nil, nil)
assert.NoError(t, err)
dialer := &honeybeetest.MockDialer{
DialContextFunc: func(context.Context, string, http.Header) (types.Socket, *http.Response, error) {
@@ -45,6 +45,11 @@ func expectEvent(
// Tests
func TestPoolID(t *testing.T) {
_, err := NewPool(context.Background(), "", nil, nil)
assert.ErrorIs(t, err, ErrInvalidPoolID)
}
func TestPoolConnect(t *testing.T) {
t.Run("successfully adds connection", func(t *testing.T) {
pool, _ := setupPool(t)
@@ -85,7 +90,7 @@ func TestPoolConnect(t *testing.T) {
func TestPoolClose(t *testing.T) {
t.Run("channels close after pool close", func(t *testing.T) {
pool, _ := NewPool(context.Background(), nil, nil)
pool, _ := NewPool(context.Background(), "pool-1", nil, nil)
pool.Close()
_, ok := <-pool.Inbox()
assert.False(t, ok)
@@ -96,7 +101,7 @@ func TestPoolClose(t *testing.T) {
})
t.Run("connect after close returns error", func(t *testing.T) {
pool, _ := NewPool(context.Background(), nil, nil)
pool, _ := NewPool(context.Background(), "pool-1", nil, nil)
pool.Close()
err := pool.Connect("wss://test")
assert.ErrorIs(t, err, ErrPoolClosed)
@@ -154,7 +159,7 @@ func TestPoolSend(t *testing.T) {
},
}
pool, err := NewPool(context.Background(), nil, nil)
pool, err := NewPool(context.Background(), "pool-1", nil, nil)
assert.NoError(t, err)
pool.dialer = mockDialer