]> gitweb.factorcode.org Git - factor.git/blob - basis/threads/threads-tests.factor
Fix permission bits
[factor.git] / basis / threads / threads-tests.factor
1 USING: namespaces io tools.test threads kernel
2 concurrency.combinators concurrency.promises locals math
3 words ;
4 IN: threads.tests
5
6 3 "x" set
7 [ 2 "x" set ] "Test" spawn drop
8 [ 2 ] [ yield "x" get ] unit-test
9 [ ] [ [ flush ] "flush test" spawn drop flush ] unit-test
10 [ ] [ [ "Errors, errors" throw ] "error test" spawn drop ] unit-test
11 yield
12
13 [ ] [ 0.3 sleep ] unit-test
14 [ "hey" sleep ] must-fail
15
16 [ 3 ] [
17     [ 3 swap resume-with ] "Test suspend" suspend
18 ] unit-test
19
20 [ f ] [ f get-global ] unit-test
21
22 { { 0 3 6 9 12 15 18 21 24 27 } } [
23     10 [
24         0 "i" tset
25         [
26             "i" [ yield 3 + ] tchange
27         ] times yield
28         "i" tget
29     ] parallel-map
30 ] unit-test
31
32 [ [ 3 throw ] "A" suspend ] [ 3 = ] must-fail-with
33
34 :: spawn-namespace-test ( -- )
35     [let | p [ <promise> ] g [ gensym ] |
36         [
37             g "x" set
38             [ "x" get p fulfill ] "B" spawn drop
39         ] with-scope
40         p ?promise g eq?
41     ] ;
42
43 [ t ] [ spawn-namespace-test ] unit-test
44
45 [ "a" [ 1 1 + ] spawn 100 sleep ] must-fail