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