;;; SPDX-License-Identifier: LGPL-3.0-or-later
;;; SPDX-FileCopyrightText: Copyright © 2010-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>

#lang syndicate/test-implementation
;; A client observing some part of the server's dataspace should cause
;; creation of an assertion of observation in that server's dataspace.

(require (only-in syndicate/lang activate))
(require syndicate/distributed)

(require (submod syndicate/distributed/heartbeat for-testing))
(heartbeats-enabled? #f)

(assertion-struct presence (who))

(define test-address (server-loopback-connection "test"))

(test-case
    [(activate syndicate/distributed)

     (spawn #:name 'producer
            (during (server-connected test-address)
              (assert (to-server test-address (presence 'producer)))))

     (spawn #:name 'consumer
            (during (server-connected test-address)
              (on (asserted (from-server test-address (presence $who)))
                  (printf "~a joined\n" who))))

     (spawn #:name 'metaconsumer
            (during (server-connected test-address)
              (on (asserted (from-server test-address (observe (presence _))))
                  (printf "Someone cares about presence!\n"))))
     ]
  no-crashes
  (expected-output (set "producer joined"
                        "Someone cares about presence!")))
