Skip to content

Commit

Permalink
feat: improve ErrClosed emitting
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Apr 28, 2022
1 parent bd326f8 commit 2c3d099
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ func TestDial(t *testing.T) {
conn := Conn(t)
require.NoError(t, conn.Ping(context.Background()))
})
t.Run("Closed", func(t *testing.T) {
ctx := context.Background()
server := cht.New(t)
conn, err := Dial(ctx, Options{
Address: server.TCP,
})
require.NoError(t, err)
require.NoError(t, conn.Ping(ctx))
require.NoError(t, conn.Close())
require.ErrorIs(t, conn.Ping(ctx), ErrClosed)
require.ErrorIs(t, conn.Do(ctx, Query{}), ErrClosed)
})
t.Run("DatabaseNotFound", func(t *testing.T) {
ctx := context.Background()
server := cht.New(t)
Expand Down
3 changes: 3 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ func (c *Client) handlePacket(ctx context.Context, p proto.ServerCode, q Query)

// Do performs Query on ClickHouse server.
func (c *Client) Do(ctx context.Context, q Query) (err error) {
if c.conn == nil {
return ErrClosed
}
if q.QueryID == "" {
q.QueryID = uuid.New().String()
}
Expand Down

0 comments on commit 2c3d099

Please sign in to comment.