1 ! Copyright (C) 2005 Chris Double. All Rights Reserved.
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: kernel threads vectors arrays sequences
5 namespaces tools.test continuations dequeues strings math words
6 match quotations concurrency.messaging concurrency.mailboxes
7 concurrency.count-downs accessors ;
8 IN: concurrency.messaging.tests
10 [ ] [ my-mailbox mailbox-data clear-dequeue ] unit-test
14 receive "received" swap reply-synchronous
15 ] "Synchronous test" spawn
16 "sent" swap send-synchronous
24 [ 2 mod 0 = not ] receive-if
31 ] "Linked test" spawn-linked drop
33 ] [ error>> "crash" = ] must-fail-with
35 MATCH-VARS: ?from ?to ?value ;
41 : counter ( value -- value ? )
43 { { increment ?value } [ ?value + t ] }
44 { { decrement ?value } [ ?value - t ] }
45 { { value ?from } [ dup ?from send t ] }
50 [ 0 [ counter ] loop ] "Counter" spawn "counter" set
51 { increment 10 } "counter" get send
52 { decrement 15 } "counter" get send
53 [ value , self , ] { } make "counter" get send
55 exit "counter" get send
60 ! 1 <count-down> "c" set
65 ! ] "Bad synchronous send" spawn "t" set
67 ! [ 3 "t" get send-synchronous ] must-fail