(t *testing.T)
| 1166 | } |
| 1167 | |
| 1168 | func 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 | |
| 1196 | func TestConnExecContextPrecanceled(t *testing.T) { |
| 1197 | t.Parallel() |
nothing calls this directly
no test coverage detected