[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.
- [gnunet-scheme] branch master updated (1f78c1e -> fd17a8f), gnunet, 2022/06/29
- [gnunet-scheme] 02/11: nse/client: Move creation of field values to the record protocol., gnunet, 2022/06/29
- [gnunet-scheme] 03/11: tests: Extract the "notify disconnected after end-of-file, after 'connected'" test from NSE.,
gnunet <=
- [gnunet-scheme] 07/11: doc: Make explanation of 'close-not-connected-no-fallbacks' more precise., gnunet, 2022/06/29
- [gnunet-scheme] 04/11: distributed-hash-table: Add a 'disconnect-after-eof-after-connected' test., gnunet, 2022/06/29
- [gnunet-scheme] 05/11: tests/distributed-hash-table: Notice an indeterministic test failure., gnunet, 2022/06/29
- [gnunet-scheme] 01/11: dht/client: Simplify by eliminating the lost-and-found field., gnunet, 2022/06/29
- [gnunet-scheme] 10/11: tests: Extract the "reconnects" test from NSE., gnunet, 2022/06/29
- [gnunet-scheme] 11/11: distributed-hash-table: Add a 'reconnects' test., gnunet, 2022/06/29
- [gnunet-scheme] 09/11: cadet: skip failing test for now to allow other tests to run., gnunet, 2022/06/29
- [gnunet-scheme] 06/11: doc: Document 'connect-after-eof-after-connected'., gnunet, 2022/06/29
- [gnunet-scheme] 08/11: Correct typo: close-not-connected-no-fallbacks -> close-not-connected-no-callbacks., gnunet, 2022/06/29