Skip to content

Commit 4890536

Browse files
GHA: Skip tests on early signaling if option 'future.plan.earlySignal' is 'defunct'
1 parent 610700e commit 4890536

File tree

1 file changed

+95
-93
lines changed

1 file changed

+95
-93
lines changed

inst/testme/test-early-signaling.R

Lines changed: 95 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -4,101 +4,74 @@
44
#' @tags deprecated
55
## plan(..., earlySignal = TRUE) is deprecated as of future (> 1.68.0)
66

7-
library(future)
8-
9-
options(future.debug = FALSE)
10-
11-
message("*** Early signaling of conditions ...")
12-
13-
message("*** Early signaling of conditions with sequential futures ...")
14-
15-
plan(sequential)
16-
f <- future({ stop("bang!") })
17-
r <- resolved(f)
18-
stopifnot(r)
19-
v <- tryCatch(value(f), error = identity)
20-
stopifnot(inherits(v, "error"))
21-
22-
message("- with lazy evaluation ...")
23-
f <- future({ stop("bang!") }, lazy = TRUE)
24-
r <- resolved(f)
25-
print(r)
26-
v <- tryCatch(value(f), error = identity)
27-
stopifnot(inherits(v, "error"))
28-
29-
## plan(..., earlySignal = TRUE) is deprecated as of future (> 1.68.0)
30-
plan(sequential, earlySignal = TRUE)
31-
f <- tryCatch(future({ stop("bang!") }), error = identity)
32-
stopifnot(inherits(f, "error"))
33-
34-
message("- with lazy evaluation ...")
35-
36-
## Errors
37-
f <- future({ stop("bang!") }, lazy = TRUE)
38-
r <- tryCatch(resolved(f), error = identity)
39-
print(r)
40-
v <- tryCatch(value(f), error = identity)
41-
stopifnot(inherits(v, "error"))
42-
43-
## Warnings
44-
f <- future({ warning("careful!") }, lazy = TRUE)
45-
res <- tryCatch({
46-
r <- resolved(f)
47-
}, condition = function(w) w)
48-
str(res)
49-
stopifnot(inherits(res, "warning"))
50-
51-
## Messages
52-
f <- future({ message("hey!") }, lazy = TRUE)
53-
res <- tryCatch({
7+
## Skip test if option 'future.plan.earlySignal' is "defunct"
8+
if (!identical(getOption("future.plan.earlySignal"), "defunct")) {
9+
library(future)
10+
11+
options(future.debug = FALSE)
12+
13+
message("*** Early signaling of conditions ...")
14+
15+
message("*** Early signaling of conditions with sequential futures ...")
16+
17+
plan(sequential)
18+
f <- future({ stop("bang!") })
5419
r <- resolved(f)
55-
}, condition = function(w) w)
56-
stopifnot(inherits(res, "message"))
57-
58-
## Condition
59-
f <- future({ signalCondition(simpleCondition("hmm")) }, lazy = TRUE)
60-
res <- tryCatch({
20+
stopifnot(r)
21+
v <- tryCatch(value(f), error = identity)
22+
stopifnot(inherits(v, "error"))
23+
24+
message("- with lazy evaluation ...")
25+
f <- future({ stop("bang!") }, lazy = TRUE)
6126
r <- resolved(f)
62-
}, condition = function(w) w)
63-
stopifnot(inherits(res, "condition"))
64-
65-
message("*** Early signaling of conditions with sequential futures ... DONE")
66-
67-
68-
message("Number of available cores: ", availableCores())
69-
70-
message("*** Early signaling of conditions with multisession futures ...")
71-
72-
plan(multisession)
73-
f <- future({ stop("bang!") })
74-
Sys.sleep(0.2)
75-
r <- resolved(f)
76-
print(r)
77-
v <- tryCatch(value(f), error = identity)
78-
stopifnot(inherits(v, "error"))
79-
80-
if (availableCores() > 1L) {
27+
print(r)
28+
v <- tryCatch(value(f), error = identity)
29+
stopifnot(inherits(v, "error"))
30+
8131
## plan(..., earlySignal = TRUE) is deprecated as of future (> 1.68.0)
82-
plan(multisession, earlySignal = TRUE)
83-
f <- future({ stop("bang!") })
84-
Sys.sleep(0.2)
85-
print(f)
32+
plan(sequential, earlySignal = TRUE)
33+
f <- tryCatch(future({ stop("bang!") }), error = identity)
34+
stopifnot(inherits(f, "error"))
35+
36+
message("- with lazy evaluation ...")
37+
38+
## Errors
39+
f <- future({ stop("bang!") }, lazy = TRUE)
8640
r <- tryCatch(resolved(f), error = identity)
8741
print(r)
8842
v <- tryCatch(value(f), error = identity)
8943
stopifnot(inherits(v, "error"))
90-
} else {
91-
message("- Skipping earlySignal = TRUE with 'multisession' because availableCores() == 1")
92-
}
93-
94-
95-
message("*** Early signaling of conditions with multisession futures ... DONE")
96-
97-
98-
if (supportsMulticore()) {
99-
message("*** Early signaling of conditions with multicore futures ...")
10044

101-
plan(multicore)
45+
## Warnings
46+
f <- future({ warning("careful!") }, lazy = TRUE)
47+
res <- tryCatch({
48+
r <- resolved(f)
49+
}, condition = function(w) w)
50+
str(res)
51+
stopifnot(inherits(res, "warning"))
52+
53+
## Messages
54+
f <- future({ message("hey!") }, lazy = TRUE)
55+
res <- tryCatch({
56+
r <- resolved(f)
57+
}, condition = function(w) w)
58+
stopifnot(inherits(res, "message"))
59+
60+
## Condition
61+
f <- future({ signalCondition(simpleCondition("hmm")) }, lazy = TRUE)
62+
res <- tryCatch({
63+
r <- resolved(f)
64+
}, condition = function(w) w)
65+
stopifnot(inherits(res, "condition"))
66+
67+
message("*** Early signaling of conditions with sequential futures ... DONE")
68+
69+
70+
message("Number of available cores: ", availableCores())
71+
72+
message("*** Early signaling of conditions with multisession futures ...")
73+
74+
plan(multisession)
10275
f <- future({ stop("bang!") })
10376
Sys.sleep(0.2)
10477
r <- resolved(f)
@@ -108,7 +81,7 @@ if (supportsMulticore()) {
10881

10982
if (availableCores() > 1L) {
11083
## plan(..., earlySignal = TRUE) is deprecated as of future (> 1.68.0)
111-
plan(multicore, earlySignal = TRUE)
84+
plan(multisession, earlySignal = TRUE)
11285
f <- future({ stop("bang!") })
11386
Sys.sleep(0.2)
11487
print(f)
@@ -117,11 +90,40 @@ if (supportsMulticore()) {
11790
v <- tryCatch(value(f), error = identity)
11891
stopifnot(inherits(v, "error"))
11992
} else {
120-
message("- Skipping earlySignal = TRUE with 'multicore' because availableCores() == 1")
93+
message("- Skipping earlySignal = TRUE with 'multisession' because availableCores() == 1")
94+
}
95+
96+
97+
message("*** Early signaling of conditions with multisession futures ... DONE")
98+
99+
100+
if (supportsMulticore()) {
101+
message("*** Early signaling of conditions with multicore futures ...")
102+
103+
plan(multicore)
104+
f <- future({ stop("bang!") })
105+
Sys.sleep(0.2)
106+
r <- resolved(f)
107+
print(r)
108+
v <- tryCatch(value(f), error = identity)
109+
stopifnot(inherits(v, "error"))
110+
111+
if (availableCores() > 1L) {
112+
## plan(..., earlySignal = TRUE) is deprecated as of future (> 1.68.0)
113+
plan(multicore, earlySignal = TRUE)
114+
f <- future({ stop("bang!") })
115+
Sys.sleep(0.2)
116+
print(f)
117+
r <- tryCatch(resolved(f), error = identity)
118+
print(r)
119+
v <- tryCatch(value(f), error = identity)
120+
stopifnot(inherits(v, "error"))
121+
} else {
122+
message("- Skipping earlySignal = TRUE with 'multicore' because availableCores() == 1")
123+
}
124+
125+
message("*** Early signaling of conditions with multicore futures ... DONE")
121126
}
122127

123-
message("*** Early signaling of conditions with multicore futures ... DONE")
128+
message("*** Early signaling of conditions ... DONE")
124129
}
125-
126-
127-
message("*** Early signaling of conditions ... DONE")

0 commit comments

Comments
 (0)