MCPcopy Create free account
hub / github.com/PostHog/duckgres / newLifecycleClientConn

Function newLifecycleClientConn

server/conn_querylog_lifecycle_test.go:19–41  ·  view source on GitHub ↗

newLifecycleClientConn builds a clientConn with both reader and writer wired so the disconnect monitor's bufio.Reader.Peek doesn't dereference nil. The clientSide pipe end stays open for the duration of the test; disconnect monitoring will Peek from it harmlessly until the test ends.

(t *testing.T)

Source from the content-addressed store, hash-verified

17// wired so the disconnect monitor's bufio.Reader.Peek doesn't dereference
18// nil. The clientSide pipe end stays open for the duration of the test;
19// disconnect monitoring will Peek from it harmlessly until the test ends.
20func newLifecycleClientConn(t *testing.T) (*clientConn, func()) {
21 t.Helper()
22 serverSide, clientSide := net.Pipe()
23 out := &bytes.Buffer{}
24 ql := &QueryLogger{ch: make(chan QueryLogEntry, 100)}
25 srv := &Server{activeQueries: make(map[BackendKey]context.CancelFunc), queryLogger: ql}
26 c := &clientConn{
27 server: srv,
28 conn: serverSide,
29 reader: bufio.NewReader(serverSide),
30 writer: bufio.NewWriter(out),
31 txStatus: txStatusIdle,
32 cursors: map[string]*cursorState{},
33 portals: map[string]*portal{},
34 stmts: map[string]*preparedStmt{},
35 ctx: context.Background(),
36 }
37 cleanup := func() {
38 _ = serverSide.Close()
39 _ = clientSide.Close()
40 }
41 return c, cleanup
42}
43
44// lifecycleExecutor is a stub executor that records every Query/Exec invocation

Calls 1

CloseMethod · 0.65

Tested by

no test coverage detected