MCPcopy
hub / github.com/jackc/pgx / TestConnExecContextCanceled

Function TestConnExecContextCanceled

pgconn/pgconn_test.go:1168–1194  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1166}
1167
1168func TestConnExecContextCanceled(t *testing.T) {
1169 t.Parallel()
1170
1171 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
1172 defer cancel()
1173
1174 pgConn, err := pgconn.Connect(ctx, os.Getenv("PGX_TEST_DATABASE"))
1175 require.NoError(t, err)
1176 defer closeConn(t, pgConn)
1177 cancel()
1178
1179 ctx, cancel = context.WithTimeout(context.Background(), 100*time.Millisecond)
1180 defer cancel()
1181 multiResult := pgConn.Exec(ctx, "select 'Hello, world', pg_sleep(1)")
1182
1183 for multiResult.NextResult() {
1184 }
1185 err = multiResult.Close()
1186 assert.True(t, pgconn.Timeout(err))
1187 assert.ErrorIs(t, err, context.DeadlineExceeded)
1188 assert.True(t, pgConn.IsClosed())
1189 select {
1190 case <-pgConn.CleanupDone():
1191 case <-time.After(5 * time.Second):
1192 t.Fatal("Connection cleanup exceeded maximum time")
1193 }
1194}
1195
1196func TestConnExecContextPrecanceled(t *testing.T) {
1197 t.Parallel()

Callers

nothing calls this directly

Calls 8

ConnectFunction · 0.92
TimeoutFunction · 0.92
NextResultMethod · 0.80
CleanupDoneMethod · 0.80
closeConnFunction · 0.70
ExecMethod · 0.65
CloseMethod · 0.65
IsClosedMethod · 0.45

Tested by

no test coverage detected