]> gitweb.factorcode.org Git - factor.git/blob - basis/concurrency/mailboxes/mailboxes-tests.factor
9acce4971a93110796e53d10dc0bb1d73665cd77
[factor.git] / basis / concurrency / mailboxes / mailboxes-tests.factor
1 USING: concurrency.mailboxes concurrency.count-downs concurrency.conditions
2 vectors sequences threads tools.test math kernel strings namespaces
3 continuations calendar destructors ;
4 IN: concurrency.mailboxes.tests
5
6 { 1 1 } [ [ integer? ] mailbox-get? ] must-infer-as
7
8 [ V{ 1 2 3 } ] [
9     0 <vector>
10     <mailbox>
11     [ mailbox-get swap push ] in-thread
12     [ mailbox-get swap push ] in-thread
13     [ mailbox-get swap push ] in-thread
14     1 over mailbox-put
15     2 over mailbox-put
16     3 swap mailbox-put
17 ] unit-test
18
19 [ V{ 1 2 3 } ] [
20     0 <vector>
21     <mailbox>
22     [ [ integer? ] mailbox-get? swap push ] in-thread
23     [ [ integer? ] mailbox-get? swap push ] in-thread
24     [ [ integer? ] mailbox-get? swap push ] in-thread
25     1 over mailbox-put
26     2 over mailbox-put
27     3 swap mailbox-put
28 ] unit-test
29
30 [ V{ 1 "junk" 3 "junk2" } [ 456 ] ] [
31     0 <vector>
32     <mailbox>
33     [ [ integer? ] mailbox-get? swap push ] in-thread
34     [ [ integer? ] mailbox-get? swap push ] in-thread
35     [ [ string? ] mailbox-get? swap push ] in-thread
36     [ [ string? ] mailbox-get? swap push ] in-thread
37     1 over mailbox-put
38     "junk" over mailbox-put
39     [ 456 ] over mailbox-put
40     3 over mailbox-put
41     "junk2" over mailbox-put
42     mailbox-get
43 ] unit-test
44
45 [ { "foo" "bar" } ] [
46     <mailbox>
47     "foo" over mailbox-put
48     "bar" over mailbox-put
49     mailbox-get-all
50 ] unit-test
51
52 [
53     <mailbox> 1 seconds mailbox-get-timeout
54 ] [ timed-out-error? ] must-fail-with