2019-03-25 12:16:30 +00:00
|
|
|
#lang imperative-syndicate/test-implementation
|
|
|
|
;; Analogous to the `core/nesting-confusion.rkt` test case.
|
|
|
|
|
|
|
|
(require (only-in imperative-syndicate/lang activate))
|
2019-05-05 15:51:23 +00:00
|
|
|
(require imperative-syndicate/distributed)
|
2019-05-09 10:43:41 +00:00
|
|
|
(require imperative-syndicate/distributed/internal-protocol)
|
2019-03-25 12:16:30 +00:00
|
|
|
|
|
|
|
(assertion-struct researcher (name topic))
|
|
|
|
|
2019-05-05 15:37:03 +00:00
|
|
|
(define test-address (server-loopback-connection "test"))
|
2019-03-25 12:16:30 +00:00
|
|
|
|
|
|
|
(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
|
2019-05-05 15:51:23 +00:00
|
|
|
[(activate imperative-syndicate/distributed)
|
2019-03-25 12:16:30 +00:00
|
|
|
|
|
|
|
(spawn #:name 'tony
|
2019-05-05 11:55:16 +00:00
|
|
|
(assert (server-proposal "test" (researcher "Tony" "Computering")))
|
|
|
|
(assert (server-proposal "test" (researcher "Tony" "Bicycling"))))
|
2019-03-25 12:16:30 +00:00
|
|
|
(spawn #:name 'alice
|
2019-05-05 11:55:16 +00:00
|
|
|
(assert (server-proposal "test" (researcher "Alice" "Cryptography")))
|
|
|
|
(assert (server-proposal "test" (researcher "Alice" "Bicycling"))))
|
2019-03-25 12:16:30 +00:00
|
|
|
(spawn #:name 'eve
|
2019-05-05 11:55:16 +00:00
|
|
|
(assert (server-proposal "test" (researcher "Eve" "Cryptography")))
|
|
|
|
(assert (server-proposal "test" (researcher "Eve" "Computering")))
|
|
|
|
(assert (server-proposal "test" (researcher "Eve" "Evil"))))
|
2019-03-25 12:16:30 +00:00
|
|
|
|
|
|
|
(spawn #:name 'all-topics
|
2019-05-05 15:37:03 +00:00
|
|
|
(during (server-connected test-address)
|
|
|
|
(during (from-server test-address (researcher _ $topic))
|
2019-03-25 12:16:30 +00:00
|
|
|
(on-start (printf "Added topic: ~a\n" topic))
|
|
|
|
(on-stop (printf "Removed topic: ~a\n" topic)))))
|
|
|
|
(spawn #:name 'all-researchers
|
2019-05-05 15:37:03 +00:00
|
|
|
(during (server-connected test-address)
|
|
|
|
(during (from-server test-address (researcher $name _))
|
2019-03-25 12:16:30 +00:00
|
|
|
(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
|
2019-05-05 15:51:23 +00:00
|
|
|
[(activate imperative-syndicate/distributed)
|
2019-03-25 12:16:30 +00:00
|
|
|
|
|
|
|
(spawn #:name 'claimant
|
2019-05-05 11:55:16 +00:00
|
|
|
(assert (server-proposal "test" (claim 123)))
|
2019-03-25 12:16:30 +00:00
|
|
|
(on-start (for [(i 100)] (flush!)) (stop-current-facet)))
|
|
|
|
(spawn #:name 'monitor
|
2019-05-05 15:37:03 +00:00
|
|
|
(during (server-connected test-address)
|
|
|
|
(during (from-server test-address (claim 123))
|
2019-03-25 12:16:30 +00:00
|
|
|
(on-start (printf "Specific claim asserted\n"))
|
|
|
|
(on-stop (printf "Specific claim retracted\n")))
|
2019-05-05 15:37:03 +00:00
|
|
|
(during (from-server test-address (claim $detail))
|
2019-03-25 12:16:30 +00:00
|
|
|
(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
|
2019-05-05 15:51:23 +00:00
|
|
|
[(activate imperative-syndicate/distributed)
|
2019-03-25 12:16:30 +00:00
|
|
|
|
|
|
|
(spawn #:name 'inner-monitor
|
2019-05-05 15:37:03 +00:00
|
|
|
(during (server-connected test-address)
|
|
|
|
(during (from-server test-address (claim $detail))
|
2019-03-25 12:16:30 +00:00
|
|
|
(on-start (printf "Inner saw claim asserted\n"))
|
|
|
|
(on-stop (printf "Inner saw claim retracted\n")))))
|
|
|
|
(spawn #:name 'claimant
|
2019-05-05 11:55:16 +00:00
|
|
|
(assert (server-proposal "test" (claim 123)))
|
2019-03-25 12:16:30 +00:00
|
|
|
(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")))
|