[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.
- [gnunet-scheme] 189/324: ROADMAP: Mark ‘Document NSE’ as done, (continued)
- [gnunet-scheme] 189/324: ROADMAP: Mark ‘Document NSE’ as done, gnunet, 2021/09/21
- [gnunet-scheme] 188/324: nse/client: Document the optionality of callbacks., gnunet, 2021/09/21
- [gnunet-scheme] 187/324: doc: Document the ‘network size estimation’ API., gnunet, 2021/09/21
- [gnunet-scheme] 197/324: mq-impl/stream: Stop all fibers when EOF is reached (part 2)., gnunet, 2021/09/21
- [gnunet-scheme] 165/324: mq-impl/stream: Implement connecting to unix sockets., gnunet, 2021/09/21
- [gnunet-scheme] 171/324: util/struct: Define /time-absolute., gnunet, 2021/09/21
- [gnunet-scheme] 168/324: README: Remove paragraph about avoiding callbacks., gnunet, 2021/09/21
- [gnunet-scheme] 175/324: mq/handler: Handle the case where no handler exists., gnunet, 2021/09/21
- [gnunet-scheme] 178/324: Makefile.am: Compile with more optimisations., gnunet, 2021/09/21
- [gnunet-scheme] 174/324: nse/struct: Add missing imports., gnunet, 2021/09/21
- [gnunet-scheme] 186/324: nse: Allow 'updated' to be absent.,
gnunet <=
- [gnunet-scheme] 166/324: guix: Use fixed version of guile., gnunet, 2021/09/21
- [gnunet-scheme] 176/324: tests/utils: New utilities for tests., gnunet, 2021/09/21
- [gnunet-scheme] 172/324: crypto/struct: Define /ecc-signature-purpose., gnunet, 2021/09/21
- [gnunet-scheme] 179/324: nse/struct: Document 'timestamp' field of estimates., gnunet, 2021/09/21
- [gnunet-scheme] 192/324: tests/mq-stream: Recognise the 'input:regular-end-of-file' error., gnunet, 2021/09/21
- [gnunet-scheme] 206/324: mq-impl/stream: Flush the output port regularily., gnunet, 2021/09/21
- [gnunet-scheme] 198/324: doc: Document dependencies and how to get the source code., gnunet, 2021/09/21
- [gnunet-scheme] 202/324: mq-impl/stream: Allow the write fiber to stop even if blocking., gnunet, 2021/09/21
- [gnunet-scheme] 205/324: tests/mq-stream: Unbreak SIGPIPE signal handler., gnunet, 2021/09/21
- [gnunet-scheme] 203/324: tests/mq-stream: Make tests less fragile., gnunet, 2021/09/21