Debian Codegraph @

inst/testme/test-startup.R

raw
1 library(parallelly)
2
3 pkgname <- "parallelly"
4 .onLoad <- parallelly:::.onLoad
5
6 maxCores <- min(2L, availableCores(methods = "system"))
7
8
9 message("*** .onLoad() ...")
10
11 message("- .onLoad() w/ parallelly.availableCores.system = 1L ...")
12 options(parallelly.availableCores.system = 1L)
13 .onLoad(pkgname, pkgname)
14 options(parallelly.availableCores.system = NULL)
15 message("- .onLoad() w/ parallelly.availableCores.system = 1L ... DONE")
16
17 message("- .onLoad() w/ R_PARALLELLY_AVAILABLECORES_SYSTEM ...")
18 Sys.setenv(R_PARALLELLY_AVAILABLECORES_SYSTEM = "1")
19 .onLoad(pkgname, pkgname)
20 ncores <- getOption("parallelly.availableCores.system")
21 print(ncores)
22 stopifnot(is.integer(ncores), ncores == 1L)
23 Sys.unsetenv("R_PARALLELLY_AVAILABLECORES_SYSTEM")
24 options(parallelly.availableCores.system = NULL)
25
26 Sys.setenv(R_PARALLELLY_AVAILABLECORES_SYSTEM = "NA")
27 .onLoad(pkgname, pkgname)
28 ncores <- getOption("parallelly.availableCores.system")
29 print(ncores)
30 stopifnot(is.integer(ncores), is.na(ncores))
31 Sys.unsetenv("R_PARALLELLY_AVAILABLECORES_SYSTEM")
32 options(parallelly.availableCores.system = NULL)
33
34 Sys.setenv(R_PARALLELLY_AVAILABLECORES_SYSTEM = "NA_real_")
35 .onLoad(pkgname, pkgname)
36 ncores <- getOption("parallelly.availableCores.system")
37 print(ncores)
38 stopifnot(is.integer(ncores), is.na(ncores))
39 Sys.unsetenv("R_PARALLELLY_AVAILABLECORES_SYSTEM")
40 options(parallelly.availableCores.system = NULL)
41
42 message("- .onLoad() w/ R_PARALLELLY_AVAILABLECORES_SYSTEM ... DONE")
43
44
45 message("- .onLoad() w/ parallelly.availableCores.fallback = 1L ...")
46 options(parallelly.availableCores.fallback = 1L)
47 .onLoad(pkgname, pkgname)
48 options(parallelly.availableCores.fallback = NULL)
49 message("- .onLoad() w/ parallelly.availableCores.fallback = 1L ... DONE")
50
51 message("- .onLoad() w/ R_PARALLELLY_AVAILABLECORES_FALLBACK ...")
52 Sys.setenv(R_PARALLELLY_AVAILABLECORES_FALLBACK = "1")
53 .onLoad(pkgname, pkgname)
54 ncores <- getOption("parallelly.availableCores.fallback")
55 print(ncores)
56 stopifnot(is.integer(ncores), ncores == 1L)
57 Sys.unsetenv("R_PARALLELLY_AVAILABLECORES_FALLBACK")
58 options(parallelly.availableCores.fallback = NULL)
59
60 Sys.setenv(R_PARALLELLY_AVAILABLECORES_FALLBACK = "NA")
61 .onLoad(pkgname, pkgname)
62 ncores <- getOption("parallelly.availableCores.fallback")
63 print(ncores)
64 stopifnot(is.integer(ncores), is.na(ncores))
65 Sys.unsetenv("R_PARALLELLY_AVAILABLECORES_FALLBACK")
66 options(parallelly.availableCores.fallback = NULL)
67
68 Sys.setenv(R_PARALLELLY_AVAILABLECORES_FALLBACK = "NA_real_")
69 .onLoad(pkgname, pkgname)
70 ncores <- getOption("parallelly.availableCores.fallback")
71 print(ncores)
72 stopifnot(is.integer(ncores), is.na(ncores))
73 Sys.unsetenv("R_PARALLELLY_AVAILABLECORES_FALLBACK")
74 options(parallelly.availableCores.fallback = NULL)
75
76 message("- .onLoad() w/ R_PARALLELLY_AVAILABLECORES_FALLBACK ... DONE")
77
78 message("*** .onLoad() ... DONE")