]> gitweb.factorcode.org Git - factor.git/blob - basis/io/monitors/monitors-tests.factor
d08441603005dd00801f6ae56a22fbc16b56dcd1
[factor.git] / basis / io / monitors / monitors-tests.factor
1 USING: io.monitors tools.test io.files system sequences
2 continuations namespaces concurrency.count-downs kernel io
3 threads calendar prettyprint destructors io.timeouts
4 io.files.temp io.directories io.directories.hierarchy
5 io.pathnames accessors concurrency.promises ;
6 IN: io.monitors.tests
7
8 os { winnt linux macosx } member? [
9     [
10         [ "monitor-test" temp-file delete-tree ] ignore-errors
11
12         [ ] [ "monitor-test" temp-file make-directory ] unit-test
13
14         [ ] [ "monitor-test" temp-file t <monitor> "m" set ] unit-test
15
16         [ ] [ "monitor-test/a1" temp-file make-directory ] unit-test
17
18         [ ] [ "monitor-test/a2" temp-file make-directory ] unit-test
19
20         [ ] [ "monitor-test/a1" temp-file "monitor-test/a2" temp-file move-file-into ] unit-test
21
22         [ t ] [ "monitor-test/a2/a1" temp-file exists? ] unit-test
23
24         [ ] [ "monitor-test/a2/a1/a3.txt" temp-file touch-file ] unit-test
25
26         [ t ] [ "monitor-test/a2/a1/a3.txt" temp-file exists? ] unit-test
27
28         [ ] [ "monitor-test/a2/a1/a4.txt" temp-file touch-file ] unit-test
29         [ ] [ "monitor-test/a2/a1/a5.txt" temp-file touch-file ] unit-test
30         [ ] [ "monitor-test/a2/a1/a4.txt" temp-file delete-file ] unit-test
31         [ ] [ "monitor-test/a2/a1/a5.txt" temp-file "monitor-test/a2/a1/a4.txt" temp-file move-file ] unit-test
32
33         [ t ] [ "monitor-test/a2/a1/a4.txt" temp-file exists? ] unit-test
34
35         [ ] [ "m" get dispose ] unit-test
36     ] with-monitors
37
38     [
39         [ "monitor-test" temp-file delete-tree ] ignore-errors
40         
41         [ ] [ "monitor-test/xyz" temp-file make-directories ] unit-test
42         
43         [ ] [ "monitor-test" temp-file t <monitor> "m" set ] unit-test
44         
45         [ ] [ 1 <count-down> "b" set ] unit-test
46         
47         [ ] [ 1 <count-down> "c1" set ] unit-test
48         
49         [ ] [ 1 <count-down> "c2" set ] unit-test
50         
51         [ ] [
52             [
53                 "b" get count-down
54
55                 [
56                     "m" get next-change path>>
57                     dup print flush
58                     dup parent-directory
59                     [ trim-tail-separators "xyz" tail? ] either? not
60                 ] loop
61
62                 "c1" get count-down
63                 
64                 [
65                     "m" get next-change path>>
66                     dup print flush
67                     dup parent-directory
68                     [ trim-tail-separators "yxy" tail? ] either? not
69                 ] loop
70
71                 "c2" get count-down
72             ] "Monitor test thread" spawn drop
73         ] unit-test
74         
75         [ ] [ "b" get await ] unit-test
76         
77         [ ] [ "monitor-test/xyz/test.txt" temp-file touch-file ] unit-test
78
79         [ ] [ "c1" get 1 minutes await-timeout ] unit-test
80         
81         [ ] [ "monitor-test/subdir/blah/yxy" temp-file make-directories ] unit-test
82
83         [ ] [ "monitor-test/subdir/blah/yxy/test.txt" temp-file touch-file ] unit-test
84
85         [ ] [ "c2" get 1 minutes await-timeout ] unit-test
86
87         ! Dispose twice
88         [ ] [ "m" get dispose ] unit-test
89
90         [ ] [ "m" get dispose ] unit-test
91     ] with-monitors
92
93     ! Out-of-scope disposal should not fail
94     [ ] [ [ "" resource-path f <monitor> ] with-monitors dispose ] unit-test
95     [ ] [ [ "" resource-path t <monitor> ] with-monitors dispose ] unit-test
96     
97     ! Timeouts
98     [
99         [ ] [ "monitor-timeout-test" temp-file make-directories ] unit-test
100
101         ! Non-recursive
102         [ ] [ "monitor-timeout-test" temp-file f <monitor> "m" set ] unit-test
103         [ ] [ 3 seconds "m" get set-timeout ] unit-test
104         [ [ t ] [ "m" get next-change drop ] while ] must-fail
105         [ ] [ "m" get dispose ] unit-test
106
107         ! Recursive
108         [ ] [ "monitor-timeout-test" temp-file t <monitor> "m" set ] unit-test
109         [ ] [ 3 seconds "m" get set-timeout ] unit-test
110         [ [ t ] [ "m" get next-change drop ] while ] must-fail
111         [ ] [ "m" get dispose ] unit-test
112     ] with-monitors
113
114     ! Disposing a monitor should throw an error in any threads
115     ! waiting on notifications
116     [
117         [ ] [
118             <promise> "p" set
119             "monitor-test" temp-file t <monitor> "m" set
120             10 seconds "m" get set-timeout
121         ] unit-test
122
123         [
124             [ "m" get next-change ] [ ] recover
125             "p" get fulfill
126         ] in-thread
127
128         [ ] [ 1 seconds sleep ] unit-test
129         [ ] [ "m" get dispose ] unit-test
130         [ t ] [ "p" get 10 seconds ?promise-timeout already-disposed? ] unit-test
131     ] with-monitors
132 ] when