|
262 | 262 | (should (memq req1 unsubed-reqs)) |
263 | 263 | (should (equal initial-msgs (reverse client-msgs))))))) |
264 | 264 |
|
| 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 | + |
265 | 336 | ;; - `seq-elt' |
266 | 337 | ;; - `seq-length' |
267 | 338 | ;; - `seq-do' |
|
0 commit comments