Make the alarm test wait for the promise to be fulfilled instead of returning immediately and failing

db4
Doug Coleman 2010-05-21 20:03:32 -05:00
parent 896949fbb8
commit 4116d8a159
1 changed files with 8 additions and 7 deletions

View File

@ -1,12 +1,12 @@
USING: alarms alarms.private kernel calendar sequences USING: alarms alarms.private calendar concurrency.count-downs
tools.test threads concurrency.count-downs concurrency.promises concurrency.promises fry kernel math math.order sequences
fry tools.time math ; threads tools.test tools.time ;
IN: alarms.tests IN: alarms.tests
[ ] [ [ ] [
1 <count-down> 1 <count-down>
{ f } clone 2dup { f } clone 2dup
[ first cancel-alarm count-down ] 2curry 1 seconds later [ first stop-alarm count-down ] 2curry 1 seconds later
swap set-first swap set-first
await await
] unit-test ] unit-test
@ -19,13 +19,14 @@ IN: alarms.tests
[ t ] [ [ t ] [
[ [
<promise> <promise>
'[ t _ fulfill ] 5 seconds later drop [ '[ t _ fulfill ] 2 seconds later drop ]
] benchmark 4,000,000,000 > [ 5 seconds ?promise-timeout drop ] bi
] benchmark 1,500,000,000 2,500,000,000 between?
] unit-test ] unit-test
[ { 3 } ] [ [ { 3 } ] [
{ 3 } dup { 3 } dup
'[ 4 _ set-first ] 2 seconds later '[ 4 _ set-first ] 2 seconds later
1/2 seconds sleep 1/2 seconds sleep
cancel-alarm stop-alarm
] unit-test ] unit-test