gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-scheme] 03/03: tests: Test reconnecting and 'start-get!'.


From: gnunet
Subject: [gnunet-scheme] 03/03: tests: Test reconnecting and 'start-get!'.
Date: Tue, 15 Feb 2022 18:42:55 +0100

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 8751c9c8b8d604e7b66433bc9cc9f9e843201c38
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Tue Feb 15 17:41:20 2022 +0000

    tests: Test reconnecting and 'start-get!'.
    
    * tests/distributed-hash-table.scm
      ("searches restarted after disconnect"): New test.
---
 tests/distributed-hash-table.scm | 46 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/tests/distributed-hash-table.scm b/tests/distributed-hash-table.scm
index 9137521..1cf6777 100644
--- a/tests/distributed-hash-table.scm
+++ b/tests/distributed-hash-table.scm
@@ -47,6 +47,7 @@
        (fibers conditions)
        (fibers channels)
        (fibers operations)
+       (fibers scheduler)
        (fibers timers) ; sleep
        (tests utils))
 
@@ -814,4 +815,49 @@ supported.  When @var{explode} is signalled, the 
connection is closed."
         (loop (+ n 1))))
      #true)))
 
+(test-assert "searches restarted after disconnect"
+  (let ((stop-first-server (make-condition))
+       (first-accepted (make-condition)))
+    (call-with-services/fibers
+     `(("dht" . ,(lambda args
+                  (if (signal-condition! first-accepted)
+                      (apply (simulate-dht-service stop-first-server) args)
+                      (apply (simulate-dht-service) args)))))
+     (lambda (config spawn-fiber)
+       (define connected/condition (make-condition))
+       (define disconnected/condition (make-condition))
+       (define (connected)
+        (signal-condition! connected/condition))
+       (define (disconnected)
+        (signal-condition! disconnected/condition))
+       (define server (connect config #:connected connected
+                              #:disconnected disconnected
+                              #:spawn spawn-fiber))
+       ;; Start a search
+       (define datum (make-a-datum))
+       (define found/condition (make-condition))
+       (define (found search-result)
+        (unless (datum=? datum (search-result->datum search-result))
+          (error "wrong search result"))
+        (unless (signal-condition! found/condition)
+          (error "multiple results")))
+       (define query (make-query (datum-type datum) (datum-key datum)))
+       (define search (start-get! server query found))
+       ;; Give @var{server} a chance to actually send the request.
+       ;; Removing the 'let loop' is possible, but would test some
+       ;; different code paths (TODO enveloppe confirmation/cancellation).
+       (wait connected/condition)
+       (wait first-accepted)
+       (let loop ((n 0))
+        (when (< n 100)
+          (yield-current-task)))
+       ;; Break the connection, letting @var{server} reconnect.
+       (signal-condition! stop-first-server)
+       (wait disconnected/condition)
+       ;; Insert the datum, such that @var{search} can complete (assuming
+       ;; that @var{server} remembered to start the search again!).
+       (put! server (datum->insertion datum))
+       (wait found/condition)
+       #true))))
+
 (test-end)

-- 
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]