gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet-scheme] 03/11: tests: Extract the "notify disconnected after end


From: gnunet
Subject: [gnunet-scheme] 03/11: tests: Extract the "notify disconnected after end-of-file, after 'connected'" test from NSE.
Date: Thu, 30 Jun 2022 00:49:23 +0200

This is an automated email from the git hooks/post-receive script.

maxime-devos pushed a commit to branch master
in repository gnunet-scheme.

commit f7e60a6ceeda14be1bba1d0a15a5aad9dd1c54a0
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Wed Jun 29 22:15:54 2022 +0000

    tests: Extract the "notify disconnected after end-of-file, after 
'connected'" test from NSE.
    
    It's also useful for DHT!
    
    * tests/network-size.scm ("notify disconnected after end-of-file,
    after 'connected'"): Generalise to ...
    * tests/utils.scm (disconnect-after-eof-after-connected): ... this
    new procedure.
---
 tests/network-size.scm | 25 +------------------------
 tests/utils.scm        | 32 +++++++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/tests/network-size.scm b/tests/network-size.scm
index 8f8e6bb..82f485d 100644
--- a/tests/network-size.scm
+++ b/tests/network-size.scm
@@ -185,30 +185,7 @@
      #t)))
 
 (test-assert "notify disconnected after end-of-file, after 'connected'"
-  (call-with-services/fibers
-   `(("nse" . ,(lambda (port spawn-fiber)
-                (close-port port))))
-   (lambda (config spawn-fiber)
-     (define disconnected? #f)
-     (define connected? #f)
-     (define c (make-condition))
-     (define (connected)
-       (set! connected? #t))
-     (define (disconnected)
-       (assert connected?)
-       ;; Because (gnu gnunet nse client) automatically reconnects,
-       ;; the following commented-out assertion can be false.
-       #;(assert (not disconnected?))
-       (set! disconnected? #t)
-       (signal-condition! c))
-     (define server
-       (nse:connect config #:spawn spawn-fiber #:connected connected
-                   #:disconnected disconnected))
-     (wait c)
-     ;; Give (gnu gnunet nse client) a chance to (incorrectly) call
-     ;; disconnected again.
-     (sleep 0.001)
-     #t)))
+  (disconnect-after-eof-after-connected "nse" nse:connect))
 
 (define forever (make-condition))
 
diff --git a/tests/utils.scm b/tests/utils.scm
index fb41ef3..020f79d 100644
--- a/tests/utils.scm
+++ b/tests/utils.scm
@@ -40,7 +40,8 @@
                             trivial-service-config
                             #{don't-call-me}#
                             close-not-connected-no-fallbacks
-                            garbage-collectable))
+                            garbage-collectable
+                            disconnect-after-eof-after-connected))
 
 (define (make-nonblocking! sock)
   (fcntl sock F_SETFL
@@ -267,3 +268,32 @@ fiber exit and the fibers do not keep a reference to the 
service object."
     (if (>= trials n-trials)
        (>= (/ successes trials) (if (conservative-gc?) 8/10 1))
        (loop (if (test) (+ 1 successes) successes) (+ 1 trials)))))
+
+(define (disconnect-after-eof-after-connected service connect)
+  "Test that when connected to a sevice and an end-of-file is encountered,
+the disconnection callback is called and that the disconnection callback
+is called after the connection callback."
+  (call-with-services/fibers
+   `((,service . ,(lambda (port spawn-fiber)
+                   (close-port port))))
+   (lambda (config spawn-fiber)
+     (define disconnected? #f)
+     (define connected? #f)
+     (define c (make-condition))
+     (define (connected)
+       (set! connected? #t))
+     (define (disconnected)
+       (assert connected?)
+       ;; Because (gnu gnunet SERVICE client) automatically reconnects,
+       ;; the following commented-out assertion can be false.
+       #;(assert (not disconnected?))
+       (set! disconnected? #t)
+       (signal-condition! c))
+     (define server
+       (connect config #:spawn spawn-fiber #:connected connected
+               #:disconnected disconnected))
+     (wait c)
+     ;; Give (gnu gnunet SERVICE client) a chance to (incorrectly) call
+     ;; disconnected again.
+     (sleep 0.001)
+     #t)))

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]