#lang syndicate/test-implementation ;; Analogous to the `core/nesting-confusion.rkt` test case. (require (only-in syndicate/lang activate)) (require syndicate/distributed) (require syndicate/distributed/internal-protocol) (require (submod syndicate/distributed/heartbeat for-testing)) (heartbeats-enabled? #f) (assertion-struct researcher (name topic)) (define test-address (server-loopback-connection "test")) (define no-mention-of-discard (lambda () (not (memf (lambda (line) (string-contains? line "#s(discard)")) (collected-lines))))) (define-syntax-rule (correct-topics-and-researchers) (expected-output (set "Added researcher: Alice" "Added researcher: Eve" "Added researcher: Tony" "Added topic: Bicycling" "Added topic: Computering" "Added topic: Cryptography" "Added topic: Evil"))) (test-case [(activate syndicate/distributed) (spawn #:name 'tony (assert (server-proposal "test" (researcher "Tony" "Computering"))) (assert (server-proposal "test" (researcher "Tony" "Bicycling")))) (spawn #:name 'alice (assert (server-proposal "test" (researcher "Alice" "Cryptography"))) (assert (server-proposal "test" (researcher "Alice" "Bicycling")))) (spawn #:name 'eve (assert (server-proposal "test" (researcher "Eve" "Cryptography"))) (assert (server-proposal "test" (researcher "Eve" "Computering"))) (assert (server-proposal "test" (researcher "Eve" "Evil")))) (spawn #:name 'all-topics (during (server-connected test-address) (during (from-server test-address (researcher _ $topic)) (on-start (printf "Added topic: ~a\n" topic)) (on-stop (printf "Removed topic: ~a\n" topic))))) (spawn #:name 'all-researchers (during (server-connected test-address) (during (from-server test-address (researcher $name _)) (on-start (printf "Added researcher: ~a\n" name)) (on-stop (printf "Removed researcher: ~a\n" name)))))] no-crashes no-mention-of-discard (correct-topics-and-researchers)) ;;--------------------------------------------------------------------------- (assertion-struct claim (detail)) (define (asserts-then-retractions) (and (equal? (length (collected-lines)) 4) (equal? (list->set (take (collected-lines) 2)) (set "Specific claim asserted" "Nonspecific claim 123 asserted")) (equal? (list->set (drop (collected-lines) 2)) (set "Specific claim retracted" "Nonspecific claim 123 retracted")))) (test-case [(activate syndicate/distributed) (spawn #:name 'claimant (assert (server-proposal "test" (claim 123))) (on-start (for [(i 100)] (flush!)) (stop-current-facet))) (spawn #:name 'monitor (during (server-connected test-address) (during (from-server test-address (claim 123)) (on-start (printf "Specific claim asserted\n")) (on-stop (printf "Specific claim retracted\n"))) (during (from-server test-address (claim $detail)) (on-start (printf "Nonspecific claim ~v asserted\n" detail)) (on-stop (printf "Nonspecific claim ~v retracted\n" detail)))))] no-crashes asserts-then-retractions) ;;--------------------------------------------------------------------------- (test-case [(activate syndicate/distributed) (spawn #:name 'inner-monitor (during (server-connected test-address) (during (from-server test-address (claim $detail)) (on-start (printf "Inner saw claim asserted\n")) (on-stop (printf "Inner saw claim retracted\n"))))) (spawn #:name 'claimant (assert (server-proposal "test" (claim 123))) (on-start (printf "Outer claimant started\n")) (on-stop (printf "Outer claimant stopped\n")) (on-start (for [(i 100)] (flush!)) (printf "Stopping outer claimant\n") (stop-current-facet)))] no-crashes (expected-output (list "Outer claimant started" "Inner saw claim asserted" "Stopping outer claimant" "Outer claimant stopped" "Inner saw claim retracted")))