X-Git-Url: https://jxself.org/git/?p=8sync.git;a=blobdiff_plain;f=tests%2Ftest-actors.scm;h=ea0324cd0bed6206be783a4e8755857c16b843b9;hp=68a05bf13a1b3c668f5c76430862fd06fe6410b1;hb=1c7504b3ea4ead41410c660702eccf70b6556363;hpb=c769bb3b2c949c304eb4395d3f24eebea6106c1a diff --git a/tests/test-actors.scm b/tests/test-actors.scm index 68a05bf..ea0324c 100644 --- a/tests/test-actors.scm +++ b/tests/test-actors.scm @@ -139,5 +139,47 @@ lazy-rep> I'm not answering that. customer> Whaaaaat? I can't believe I got voice mail!\n" displayed-text)))) + +;;; Cleanup tests + +(define-simple-actor + (*cleanup* test-call-cleanup)) + +(define (test-call-cleanup actor message) + (speak "Hey, I'm cleanin' up here!\n")) + +(with-fresh-speaker + (let ((hive (make-hive))) + (hive-create-actor hive ) + (run-hive hive '())) + (test-equal '("Hey, I'm cleanin' up here!\n") + (get-spoken))) + +;; won't work if we turn off #:cleanup though + +(with-fresh-speaker + (let ((hive (make-hive))) + (hive-create-actor hive ) + (run-hive hive '() #:cleanup #f)) + (test-equal '() + (get-spoken))) + +;; The exploder self-destructs, even though run-hive has cleanup +;; disabled, because it cleans up on self-destruct. + +(define-simple-actor + (explode (lambda (exploder message) + (speak "POOF\n") + (self-destruct exploder))) + (*cleanup* (lambda _ (speak "Cleaning up post-explosion\n")))) + +(with-fresh-speaker + (let ((hive (make-hive))) + (define exploder (hive-create-actor hive )) + (run-hive hive (list (bootstrap-message hive exploder 'explode)) + #:cleanup #f)) + (get-spoken)) + + (test-end "test-actors") (test-exit)