1
1
context(" checkInterrupts" )
2
2
3
- test_that(" check_interrupts = TRUE works with queries < 1 second (#244) " , {
3
+ test_that(" check_interrupts = TRUE works with queries < 1 second" , {
4
4
con <- postgresDefault(check_interrupts = TRUE )
5
5
time <- system.time(
6
6
expect_equal(dbGetQuery(con , " SELECT pg_sleep(0.2), 'foo' AS x" )$ x , " foo" )
@@ -9,6 +9,15 @@ test_that("check_interrupts = TRUE works with queries < 1 second (#244)", {
9
9
dbDisconnect(con )
10
10
})
11
11
12
+ test_that(" check_interrupts = TRUE works with queries > 1 second (#244)" , {
13
+ con <- postgresDefault(check_interrupts = TRUE )
14
+ time <- system.time(
15
+ expect_equal(dbGetQuery(con , " SELECT pg_sleep(2), 'foo' AS x" )$ x , " foo" )
16
+ )
17
+ expect_gt(time [[" elapsed" ]], 1.5 )
18
+ dbDisconnect(con )
19
+ })
20
+
12
21
test_that(" check_interrupts = TRUE interrupts immediately (#336)" , {
13
22
skip_if_not(postgresHasDefault())
14
23
skip_if(Sys.getenv(" R_COVR" ) != " " )
@@ -20,6 +29,8 @@ test_that("check_interrupts = TRUE interrupts immediately (#336)", {
20
29
session $ run(function () {
21
30
library(RPostgres )
22
31
.GlobalEnv $ conn <- postgresDefault(check_interrupts = TRUE )
32
+ .GlobalEnv $ connPid <- dbGetQuery(.GlobalEnv $ conn , " SELECT pg_backend_pid() AS pid" )$ pid
33
+ .GlobalEnv $ checkConn <- postgresDefault()
23
34
invisible ()
24
35
})
25
36
@@ -31,8 +42,13 @@ test_that("check_interrupts = TRUE interrupts immediately (#336)", {
31
42
session $ interrupt()
32
43
# Interrupts are slow on Windows, give ample time
33
44
expect_equal(session $ poll_process(2000 ), " ready" )
45
+ session $ read()
46
+
47
+ queryStatus = session $ run(function () {
48
+ dbGetQuery(.GlobalEnv $ checkConn , " SELECT state FROM pg_stat_activity WHERE pid = $1" , params = .GlobalEnv $ connPid )
49
+ })
50
+ expect_equal(queryStatus $ state , " idle" )
34
51
35
- # Tests for error behavior are brittle
36
52
37
53
session $ close()
38
54
})
0 commit comments