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 ;
8 os { winnt linux macosx } member? [
10 [ "monitor-test" temp-file delete-tree ] ignore-errors
12 [ ] [ "monitor-test" temp-file make-directory ] unit-test
14 [ ] [ "monitor-test" temp-file t <monitor> "m" set ] unit-test
16 [ ] [ "monitor-test/a1" temp-file make-directory ] unit-test
18 [ ] [ "monitor-test/a2" temp-file make-directory ] unit-test
20 [ ] [ "monitor-test/a1" temp-file "monitor-test/a2" temp-file move-file-into ] unit-test
22 [ t ] [ "monitor-test/a2/a1" temp-file exists? ] unit-test
24 [ ] [ "monitor-test/a2/a1/a3.txt" temp-file touch-file ] unit-test
26 [ t ] [ "monitor-test/a2/a1/a3.txt" temp-file exists? ] unit-test
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
33 [ t ] [ "monitor-test/a2/a1/a4.txt" temp-file exists? ] unit-test
35 [ ] [ "m" get dispose ] unit-test
39 [ "monitor-test" temp-file delete-tree ] ignore-errors
41 [ ] [ "monitor-test/xyz" temp-file make-directories ] unit-test
43 [ ] [ "monitor-test" temp-file t <monitor> "m" set ] unit-test
45 [ ] [ 1 <count-down> "b" set ] unit-test
47 [ ] [ 1 <count-down> "c1" set ] unit-test
49 [ ] [ 1 <count-down> "c2" set ] unit-test
56 "m" get next-change path>>
59 [ trim-tail-separators "xyz" tail? ] either? not
65 "m" get next-change path>>
68 [ trim-tail-separators "yxy" tail? ] either? not
72 ] "Monitor test thread" spawn drop
75 [ ] [ "b" get await ] unit-test
77 [ ] [ "monitor-test/xyz/test.txt" temp-file touch-file ] unit-test
79 [ ] [ "c1" get 1 minutes await-timeout ] unit-test
81 [ ] [ "monitor-test/subdir/blah/yxy" temp-file make-directories ] unit-test
83 [ ] [ "monitor-test/subdir/blah/yxy/test.txt" temp-file touch-file ] unit-test
85 [ ] [ "c2" get 1 minutes await-timeout ] unit-test
88 [ ] [ "m" get dispose ] unit-test
90 [ ] [ "m" get dispose ] unit-test
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
99 [ ] [ "monitor-timeout-test" temp-file make-directories ] unit-test
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
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
114 ! Disposing a monitor should throw an error in any threads
115 ! waiting on notifications
119 "monitor-test" temp-file t <monitor> "m" set
120 10 seconds "m" get set-timeout
124 [ "m" get next-change ] [ ] recover
128 [ ] [ 1 seconds sleep ] unit-test
129 [ ] [ "m" get dispose ] unit-test
130 [ t ] [ "p" get 10 seconds ?promise-timeout already-disposed? ] unit-test