Bug fixes for lcs.diff2html; xml.writer
[factor/jcg.git] / basis / threads / threads-tests.factor
blobadac84338d53552f2f3fbaee6a65a6a1b7edd56c
1 USING: namespaces io tools.test threads kernel
2 concurrency.combinators concurrency.promises locals math
3 words ;
4 IN: threads.tests
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
13 [ ] [ 0.3 sleep ] unit-test
14 [ "hey" sleep ] must-fail
16 [ 3 ] [
17     [ 3 swap resume-with ] "Test suspend" suspend
18 ] unit-test
20 [ f ] [ f get-global ] unit-test
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
32 [ [ 3 throw ] "A" suspend ] [ 3 = ] must-fail-with
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     ] ;
43 [ t ] [ spawn-namespace-test ] unit-test
45 [ "a" [ 1 1 + ] spawn 100 sleep ] must-fail