#lang imperative-syndicate/test-implementation

(test-case
    [(message-struct toggle ())
     (spawn* #:name 'flip-flop
             (define (even)
               (react (stop-when (message (toggle)) (odd))
                      (on-start (printf "+even\n"))
                      (on-stop  (printf "-even\n"))))
             (define (odd)
               (react (stop-when (message (toggle)) (even))
                      (on-start (printf "+odd\n"))
                      (on-stop  (printf "-odd\n"))))
             (even))
     (spawn* #:name 'main
             (until (asserted (observe (toggle))))
             (send! (toggle))
             (send! (toggle))
             (send! (toggle)))]
  no-crashes
  (expected-output (list "+even"
                         "-even"
                         "+odd"
                         "-odd"
                         "+even"
                         "-even"
                         "+odd")))
