--- Coro/t/15_semaphore.t 2008/11/16 10:33:08 1.3 +++ Coro/t/15_semaphore.t 2008/11/18 23:20:41 1.4 @@ -1,5 +1,5 @@ $|=1; -print "1..2\n"; +print "1..6\n"; use Coro; use Coro::Semaphore; @@ -34,6 +34,7 @@ print $counter == 998 ? "" : "not ", "ok 1 # $counter\n"; } +# check terminate { my $sem = new Coro::Semaphore 0; @@ -54,5 +55,50 @@ $as1->join; $as2->join; } + +# check throw +{ + my $sem = new Coro::Semaphore 0; + + $as1 = async { + my $g = eval { + $sem->guard; + }; + print $@ ? "" : "not ", "ok 3\n"; + }; + + $as2 = async { + my $g = $sem->guard; + print "ok 4\n"; + }; + + cede; + + $sem->up; # wake up as1 + $as1->throw (1); # destroy as1 before it could ->guard + $as1->join; + $as2->join; +} + +# check wait +{ + my $sem = new Coro::Semaphore 0; + + $as1 = async { + $sem->wait; + print "ok 5\n"; + }; + + $as2 = async { + my $g = $sem->guard; + print "ok 6\n"; + }; + + cede; + + $sem->up; # wake up as1 + $as1->join; + $as2->join; +}