@@ -14,12 +14,10 @@ test_that("later_fd", {
14
14
15
15
# timeout
16
16
later_fd(callback , c(fd1 , fd2 ), timeout = 0 )
17
- Sys.sleep(0.2 )
18
- run_now()
17
+ run_now(1 )
19
18
expect_equal(result , c(FALSE , FALSE ))
20
19
later_fd(callback , c(fd1 , fd2 ), exceptfds = c(fd1 , fd2 ), timeout = 0 )
21
- Sys.sleep(0.2 )
22
- run_now()
20
+ run_now(1 )
23
21
expect_equal(result , c(FALSE , FALSE , FALSE , FALSE ))
24
22
25
23
# cancellation
@@ -35,57 +33,49 @@ test_that("later_fd", {
35
33
36
34
# timeout (> 1 loop)
37
35
later_fd(callback , c(fd1 , fd2 ), timeout = 1.1 )
38
- Sys.sleep(1.25 )
39
- run_now()
36
+ run_now(1.3 )
40
37
expect_equal(result , c(FALSE , FALSE ))
41
38
42
39
# fd1 ready
43
40
later_fd(callback , c(fd1 , fd2 ), timeout = 0.9 )
44
41
res <- nanonext :: send(s2 , " msg" )
45
- Sys.sleep(0.2 )
46
- run_now()
42
+ run_now(1 )
47
43
expect_equal(result , c(TRUE , FALSE ))
48
44
49
45
# both fd1, fd2 ready
50
46
res <- nanonext :: send(s1 , " msg" )
51
47
Sys.sleep(0.1 )
52
48
later_fd(callback , c(fd1 , fd2 ), timeout = 1 )
53
- Sys.sleep(0.1 )
54
- run_now()
49
+ run_now(1 )
55
50
expect_equal(result , c(TRUE , TRUE ))
56
51
57
52
# no exceptions
58
53
later_fd(callback , c(fd1 , fd2 ), exceptfds = c(fd1 , fd2 ), timeout = - 0.1 )
59
- Sys.sleep(0.2 )
60
- run_now()
54
+ run_now(1 )
61
55
expect_equal(result , c(TRUE , TRUE , FALSE , FALSE ))
62
56
63
57
# fd2 ready
64
58
res <- nanonext :: recv(s1 )
65
59
later_fd(callback , c(fd1 , fd2 ), timeout = 1L )
66
- Sys.sleep(0.2 )
67
- run_now()
60
+ run_now(1 )
68
61
expect_equal(result , c(FALSE , TRUE ))
69
62
70
63
# fd2 invalid
71
64
res <- nanonext :: recv(s2 )
72
65
later_fd(callback , c(fd1 , fd2 ), exceptfds = c(fd1 , fd2 ), timeout = 0.1 )
73
66
close(s2 )
74
- Sys.sleep(0.2 )
75
- run_now()
67
+ run_now(1 )
76
68
expect_length(result , 4L )
77
69
78
70
# both fd1, fd2 invalid
79
71
close(s1 )
80
72
later_fd(callback , c(fd1 , fd2 ), c(fd1 , fd2 ), timeout = 0 )
81
- Sys.sleep(0.2 )
82
- run_now()
73
+ run_now(1 )
83
74
expect_equal(result , c(NA , NA , NA , NA ))
84
75
85
76
# no fds supplied
86
77
later_fd(callback , timeout = - 1 )
87
- Sys.sleep(0.2 )
88
- run_now()
78
+ run_now(1 )
89
79
expect_equal(result , logical ())
90
80
91
81
on.exit()
@@ -107,12 +97,12 @@ test_that("loop_empty() reflects later_fd callbacks", {
107
97
cancel <- later_fd(~ {}, fd1 )
108
98
expect_false(loop_empty())
109
99
cancel()
110
- Sys.sleep(1.2 ) # check for cancellation happens every ~1 sec
100
+ Sys.sleep(1.25 ) # check for cancellation happens every ~1 sec
111
101
expect_true(loop_empty())
112
102
113
103
later_fd(~ {}, fd1 , timeout = 0 )
114
104
expect_false(loop_empty())
115
- run_now()
105
+ run_now(1 )
116
106
expect_true(loop_empty())
117
107
118
108
})
0 commit comments