Skip to content

Commit 450165f

Browse files
committed
Add additional tests for publisher/subscriber interaction
* test/jupyter-monad-test.el (jupyter-subscriber-error) (jupyter-subscriber-skipping): The new tests.
1 parent f1394d3 commit 450165f

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

test/jupyter-monad-test.el

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,77 @@
262262
(should (memq req1 unsubed-reqs))
263263
(should (equal initial-msgs (reverse client-msgs)))))))
264264

265+
(ert-deftest jupyter-subscriber-error ()
266+
:tags '(monad)
267+
;; Test that a subscriber that raises an error just gets skipped
268+
;; over, not removed.
269+
(let ((called1 0)
270+
(called2 0))
271+
(let ((sub1 (jupyter-subscriber
272+
(lambda (msg)
273+
(setq called1 (1+ called1)))))
274+
(sub2 (jupyter-subscriber
275+
(lambda (msg)
276+
(setq called2 (1+ called2))
277+
(error "Subscriber error"))))
278+
(pub (jupyter-publisher #'jupyter-content)))
279+
(jupyter-run-with-io pub
280+
(jupyter-do
281+
(jupyter-subscribe sub2)
282+
(jupyter-subscribe sub1)))
283+
(should-error
284+
(jupyter-run-with-io pub
285+
(jupyter-publish 'msg)))
286+
(should (eq called1 1))
287+
(should (eq called2 1))
288+
(should-error
289+
(jupyter-run-with-io pub
290+
(jupyter-publish 'msg)))
291+
(should (eq called1 2))
292+
(should (eq called2 2))
293+
(should-error
294+
(jupyter-run-with-io pub
295+
(jupyter-publish 'msg)))
296+
(should (eq called1 3))
297+
(should (eq called2 3)))))
298+
299+
(ert-deftest jupyter-subscriber-skipping ()
300+
:tags '(monad)
301+
;; Test that subscribers evaluation doesn't get skipped whenever a
302+
;; previous subscriber unsubscribes.
303+
(let* ((count1 0)
304+
(count2 0)
305+
(count3 0)
306+
(sub1
307+
(jupyter-subscriber
308+
(lambda (msg)
309+
(setq count1 (1+ count1)))))
310+
(sub2
311+
(jupyter-subscriber
312+
(lambda (msg)
313+
(setq count2 (1+ count2))
314+
(jupyter-unsubscribe))))
315+
(sub3
316+
(jupyter-subscriber
317+
(lambda (msg)
318+
(setq count3 (1+ count3)))))
319+
(pub (jupyter-publisher #'jupyter-content)))
320+
(jupyter-run-with-io pub
321+
(jupyter-do
322+
(jupyter-subscribe sub3)
323+
(jupyter-subscribe sub2)
324+
(jupyter-subscribe sub1)))
325+
(jupyter-run-with-io pub
326+
(jupyter-publish 'msg))
327+
(should (eq count1 1))
328+
(should (eq count2 1))
329+
(should (eq count3 1))
330+
(jupyter-run-with-io pub
331+
(jupyter-publish 'msg))
332+
(should (eq count1 2))
333+
(should (eq count2 1))
334+
(should (eq count3 2))))
335+
265336
;; - `seq-elt'
266337
;; - `seq-length'
267338
;; - `seq-do'

0 commit comments

Comments
 (0)