diff options
author | Maxime Devos <maximedevos@telenet.be> | 2021-09-07 21:00:00 +0200 |
---|---|---|
committer | Maxime Devos <maximedevos@telenet.be> | 2021-09-21 12:20:58 +0200 |
commit | d52234e8113c638acef979933ae4e4ed3e9abdcb (patch) | |
tree | 5cdb75f5f6effd93894232ff71b559996a20e50b /tests | |
parent | fb8b1e5b3df15b246cd4404dcaa3bb5bf5e90634 (diff) | |
download | gnunet-scheme-d52234e8113c638acef979933ae4e4ed3e9abdcb.tar.gz gnunet-scheme-d52234e8113c638acef979933ae4e4ed3e9abdcb.zip |
mq-impl/stream: Allow closing queues made with connect-fibers.
* gnu/gnunet/mq-impl/stream.scm
(connect/fibers): Document new behaviour.
(connect/fibers)[interrupt-condition]: New variable.
(connect/fibers)[close*!]: New procedure.
(connect/fibers)[mq]: Use new procedure.
(connect/fibers)[allow-interrupt-operation]: New variable.
(connect/fibers)[sleep*]: New procedure.
(connect/fibers): Pass new 'sleep*' procedure to 'connect-unix'.
(connect/fibers): Inject 'connection:interrupted' if appropriate
instead of 'connection:connected'.
(connect-unix): Add 'sleep' argument.
* doc/scheme-gnunet.tm (Disconnecting): New section.
* tests/mq-stream.scm
("can close while still connecting (--> interrupted)")
("can close after being connected (--> regular-end-of-file)"):
New tests.
* README.org (List of errors): Note existence of 'connectin:interrupted'.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/mq-stream.scm | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/mq-stream.scm b/tests/mq-stream.scm index f5a56e6..6b1850a 100644 --- a/tests/mq-stream.scm +++ b/tests/mq-stream.scm | |||
@@ -751,4 +751,66 @@ If an EPIPE system error is raised, return #f." | |||
751 | #:parallelism 1) | 751 | #:parallelism 1) |
752 | (port-closed? alpha))) | 752 | (port-closed? alpha))) |
753 | 753 | ||
754 | (test-assert "can close while still connecting (--> interrupted)" | ||
755 | (call-with-socket-location | ||
756 | (lambda (where config) | ||
757 | (call-with-spawner/wait | ||
758 | (lambda (spawn) | ||
759 | (define interrupted? #f) | ||
760 | (define cond (make-condition)) | ||
761 | (define (error-handler . e) | ||
762 | (match e | ||
763 | ('(connection:interrupted) | ||
764 | (begin | ||
765 | (pk 'interrupted) | ||
766 | (assert (not interrupted?)) | ||
767 | (set! interrupted? #t) | ||
768 | (signal-condition! cond))) | ||
769 | (_ (error "what ~a" e)))) | ||
770 | (define mq (connect/fibers config "service" no-handlers error-handler | ||
771 | #:spawn spawn)) | ||
772 | (close-queue! mq) | ||
773 | (wait cond) | ||
774 | #t))))) | ||
775 | |||
776 | (test-assert "can close after being connected (--> regular-end-of-file)" | ||
777 | (call-with-socket-location | ||
778 | (lambda (where config) | ||
779 | (call-with-spawner/wait | ||
780 | (lambda (spawn) | ||
781 | (define connected? #f) | ||
782 | (define connected-condition (make-condition)) | ||
783 | (define disconnected? #f) | ||
784 | (define disconnected-condition (make-condition)) | ||
785 | (define (error-handler . e) | ||
786 | (match e | ||
787 | ('(connection:connected) | ||
788 | (pk 'connected) | ||
789 | (assert (not connected?)) | ||
790 | (set! connected? #t) | ||
791 | (signal-condition! connected-condition)) | ||
792 | ('(input:regular-end-of-file) | ||
793 | (assert connected?) | ||
794 | (assert (not disconnected?)) | ||
795 | (set! disconnected? #t) | ||
796 | (signal-condition! disconnected-condition)) | ||
797 | (_ (error "what ~a" e)))) | ||
798 | (define mq (connect/fibers config "service" no-handlers error-handler | ||
799 | #:spawn spawn)) | ||
800 | (spawn | ||
801 | (lambda () | ||
802 | (define listening-sock (socket PF_UNIX SOCK_STREAM 0)) | ||
803 | (bind listening-sock AF_UNIX where) | ||
804 | (listen listening-sock 1) | ||
805 | ;; Make it non-blocking (because guile-fibers is used) | ||
806 | (fcntl listening-sock F_SETFL | ||
807 | (bitwise-ior (fcntl listening-sock F_GETFL) O_NONBLOCK)) | ||
808 | ;; Not actually interested in the return value | ||
809 | (accept listening-sock))) | ||
810 | (wait connected-condition) | ||
811 | (assert (not disconnected?)) | ||
812 | (close-queue! mq) | ||
813 | (wait disconnected-condition) | ||
814 | #t))))) | ||
815 | |||
754 | (test-end "mq-stream") | 816 | (test-end "mq-stream") |