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