File: BatchtoolsFuture.R

package info (click to toggle)
r-cran-future.batchtools 0.12.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 528 kB
  • sloc: sh: 82; makefile: 2
file content (100 lines) | stat: -rw-r--r-- 2,105 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
source("incl/start.R")

message("*** BatchtoolsFuture() ...")

message("*** BatchtoolsFuture() - cleanup ...")

f <- batchtools_local({ 1L })
res <- await(f, cleanup = TRUE)
print(res)
stopifnot(res$value == 1L)

message("*** BatchtoolsFuture() - cleanup ... DONE")


message("*** BatchtoolsFuture() - deleting exceptions ...")

## Printing a deleted future
f <- batchtools_local(42L)
print(f)
v <- value(f)
print(v)
stopifnot(v == 42L)
res <- delete(f)
print(f)
res <- delete(f)
print(f)

message("*** BatchtoolsFuture() - deleting exceptions ... DONE")


message("*** BatchtoolsFuture() - registry exceptions ...")

## Non-existing batchtools registry
f <- BatchtoolsFuture({ x <- 1 })

## Hack to emulate where batchtools registry is deleted or fails
f$state <- "running"
if (!is.null(f$config$reg)) {
  path <- f$config$reg$file.dir
  unlink(path, recursive = TRUE)
}

res <- tryCatch({
  value(f)
}, error = function(ex) ex)
print(res)
stopifnot(inherits(res, "error"))

res <- tryCatch({
  await(f)
}, error = function(ex) ex)
print(res)
stopifnot(inherits(res, "error"))


message("*** BatchtoolsFuture() - registry exceptions ... DONE")

message("*** BatchtoolsFuture() - exceptions ...")

res <- try(f <- BatchtoolsFuture(42L, workers = integer(0)), silent = TRUE)
print(res)
stopifnot(inherits(res, "try-error"))

res <- try(f <- BatchtoolsFuture(42L, workers = 0L), silent = TRUE)
print(res)
stopifnot(inherits(res, "try-error"))

res <- try(f <- BatchtoolsFuture(42L, workers = TRUE), silent = TRUE)
print(res)
stopifnot(inherits(res, "try-error"))

message("*** BatchtoolsFuture() - exceptions ... DONE")


message("*** BatchtoolsFuture() - timeout ...")

if (fullTest && availableCores(constraints = "multicore") > 1) {
  plan(batchtools_multicore)

  options(future.wait.timeout = 0.15, future.wait.interval = 0.1)

  f <- future({
    Sys.sleep(5)
    x <- 1
  })

  res <- tryCatch({
    value(f)
  }, error = function(ex) ex)
  stopifnot(inherits(res, "error"))
}


message("*** BatchtoolsFuture() - timeout ... DONE")



message("*** BatchtoolsFuture() ... DONE")

source("incl/end.R")