gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-scheme] 186/324: nse: Allow 'updated' to be absent.


From: gnunet
Subject: [gnunet-scheme] 186/324: nse: Allow 'updated' to be absent.
Date: Tue, 21 Sep 2021 13:23:46 +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 2ca0c5b570be219b9ec9d8be81f38c2319fa32c6
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Wed Aug 18 21:11:23 2021 +0200

    nse: Allow 'updated' to be absent.
    
    Fixes: https://notabug.org/maximed/scheme-gnunet/issues/4
    
    * gnu/gnunet/nse/client.scm
      (connect)[handle-estimate]: Only call 'updated' if it isn't false.
    * tests/network-size.scm
      (act-as-the-server, estimate->list): Extract from
      "Client calls call-back (and sets estimates) in-order".
      ("likewise, without 'updated' or 'connected' (issue 4)"): Test it.
---
 gnu/gnunet/nse/client.scm |  3 +-
 tests/network-size.scm    | 82 ++++++++++++++++++++++++++++++-----------------
 2 files changed, 55 insertions(+), 30 deletions(-)

diff --git a/gnu/gnunet/nse/client.scm b/gnu/gnunet/nse/client.scm
index 8ac0d8e..dccca2d 100644
--- a/gnu/gnunet/nse/client.scm
+++ b/gnu/gnunet/nse/client.scm
@@ -133,7 +133,8 @@ procedure should accept the new estimate."
           (read% /:msg:nse:estimate '(std-deviation) estimate-slice)
           (read% /:msg:nse:estimate '(timestamp) estimate-slice)))
        (atomic-box-set! estimate/box estimate)
-       (updated estimate))
+       (when updated
+         (updated estimate)))
       (define handlers
        (message-handlers
         (make-message-handler (symbol-value message-type msg:nse:estimate)
diff --git a/tests/network-size.scm b/tests/network-size.scm
index 85efb9b..50be8e6 100644
--- a/tests/network-size.scm
+++ b/tests/network-size.scm
@@ -29,7 +29,9 @@
        (only (gnu gnunet utils bv-slice)
              slice-length make-slice/read-write)
        (only (tests utils) call-with-services/fibers)
+       (only (fibers) sleep)
        (gnu gnunet netstruct syntactic)
+       (srfi srfi-1)
        (srfi srfi-26)
        (srfi srfi-43)
        (srfi srfi-64)
@@ -83,43 +85,48 @@
              (lambda (slice) (values)))))
   (port->message-queue port h no-error-handler #:spawn spawn-fiber))
 
+(define (act-as-the-server port spawn-fiber estimates)
+  (define mq
+    (port->nse-client-message-queue port spawn-fiber))
+  ;; Send the client a few fake estimates.
+  ;; This code would be incorrect if there were
+  ;; multiple clients!
+  (define (send! estimate)
+    (define s (make-slice/read-write
+              (sizeof /:msg:nse:estimate '())))
+    ;; Set the headers
+    (set%! /:msg:nse:estimate '(header size) s
+          (sizeof /:msg:nse:estimate '()))
+    (set%! /:msg:nse:estimate '(header type) s
+          (value->index
+           (symbol-value message-type msg:nse:estimate)))
+    ;; Set the data
+    (set%! /:msg:nse:estimate '(timestamp) s
+          (list-ref estimate 3))
+    (set%! /:msg:nse:estimate '(size-estimate) s
+          (list-ref estimate 0))
+    (set%! /:msg:nse:estimate '(std-deviation) s
+          (list-ref estimate 2))
+    ;; Send the estimate
+    (send-message! mq s))
+  (for-each send! %estimates))
+
+(define (estimate->list estimate)
+  "Represent ESTIMATE as a list that can be compared with equal?."
+  `(,(nse:estimate:logarithmic-number-peers estimate)
+    ,(nse:estimate:number-peers estimate)
+    ,(nse:estimate:standard-deviation estimate)
+    ,(nse:estimate:timestamp estimate)))
+
 (test-equal "Client calls call-back (and sets estimates) in-order"
   (list %estimates %estimates)
   (call-with-services/fibers
    `(("nse" . ,(lambda (port spawn-fiber)
-                (define mq
-                  (port->nse-client-message-queue port spawn-fiber))
-                ;; Send the client a few fake estimates.
-                ;; This code would be incorrect if there were
-                ;; multiple clients!
-                (define (send! estimate)
-                  (define s (make-slice/read-write
-                             (sizeof /:msg:nse:estimate '())))
-                  ;; Set the headers
-                  (set%! /:msg:nse:estimate '(header size) s
-                         (sizeof /:msg:nse:estimate '()))
-                  (set%! /:msg:nse:estimate '(header type) s
-                         (value->index
-                          (symbol-value message-type msg:nse:estimate)))
-                  ;; Set the data
-                  (set%! /:msg:nse:estimate '(timestamp) s
-                         (list-ref estimate 3))
-                  (set%! /:msg:nse:estimate '(size-estimate) s
-                         (list-ref estimate 0))
-                  (set%! /:msg:nse:estimate '(std-deviation) s
-                         (list-ref estimate 2))
-                  ;; Send the estimate
-                  (send-message! mq s))
-                (for-each send! %estimates))))
+                (act-as-the-server port spawn-fiber %estimates))))
    (lambda (config spawn-fiber)
      (define estimates/update/reverse '())
      (define estimates/poll/reverse '())
      (define connected? #f)
-     (define (estimate->list estimate)
-       `(,(nse:estimate:logarithmic-number-peers estimate)
-        ,(nse:estimate:number-peers estimate)
-        ,(nse:estimate:standard-deviation estimate)
-        ,(nse:estimate:timestamp estimate)))
      (define done (make-condition))
      (define (updated estimate)
        (assert connected?)
@@ -146,4 +153,21 @@
      (list (reverse estimates/update/reverse)
           (reverse estimates/poll/reverse)))))
 
+;; See <https://notabug.org/maximed/scheme-gnunet/issues/4>.
+;; Only the last estimate is tested.
+
+(test-assert "likewise, without 'updated' or 'connected' (issue 4)"
+  (call-with-services/fibers
+   `(("nse" . ,(lambda (port spawn-fiber)
+                (act-as-the-server port spawn-fiber %estimates))))
+   (lambda (config spawn-fiber)
+     (define server
+       (nse:connect config #:spawn spawn-fiber))
+     (let loop ((time-delta 0))
+       (unless (equal? (and=> (nse:estimate server) estimate->list)
+                      (last %estimates))
+        (sleep (/ time-delta time-unit:second))
+        (loop (standard-back-off time-delta))))
+     #t)))
+
 (test-end "network-size")

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