tests: Properly synchronize threads in the 'home-page' lint tests.
* tests/lint.scm (%http-server-lock, %http-server-ready): New variables. (http-open): New procedure. (stub-http-server): Use it. (call-with-http-server): Wrap body in 'with-mutex'. Call 'wait-condition-variable' after 'make-thread'.
This commit is contained in:
parent
35ed9306b9
commit
4655005e24
@ -1,7 +1,7 @@
|
|||||||
;;; GNU Guix --- Functional package management for GNU
|
;;; GNU Guix --- Functional package management for GNU
|
||||||
;;; Copyright © 2012, 2013 Cyril Roelandt <tipecaml@gmail.com>
|
;;; Copyright © 2012, 2013 Cyril Roelandt <tipecaml@gmail.com>
|
||||||
;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
|
;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
|
||||||
;;; Copyright © 2014 Ludovic Courtès <ludo@gnu.org>
|
;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
@ -75,9 +75,20 @@
|
|||||||
(quit #t) ;exit the server thread
|
(quit #t) ;exit the server thread
|
||||||
(values)))
|
(values)))
|
||||||
|
|
||||||
|
;; Mutex and condition variable to synchronize with the HTTP server.
|
||||||
|
(define %http-server-lock (make-mutex))
|
||||||
|
(define %http-server-ready (make-condition-variable))
|
||||||
|
|
||||||
|
(define (http-open . args)
|
||||||
|
"Start listening for HTTP requests and signal %HTTP-SERVER-READY."
|
||||||
|
(with-mutex %http-server-lock
|
||||||
|
(let ((result (apply (@@ (web server http) http-open) args)))
|
||||||
|
(signal-condition-variable %http-server-ready)
|
||||||
|
result)))
|
||||||
|
|
||||||
(define-server-impl stub-http-server
|
(define-server-impl stub-http-server
|
||||||
;; Stripped-down version of Guile's built-in HTTP server.
|
;; Stripped-down version of Guile's built-in HTTP server.
|
||||||
(@@ (web server http) http-open)
|
http-open
|
||||||
(@@ (web server http) http-read)
|
(@@ (web server http) http-read)
|
||||||
http-write
|
http-write
|
||||||
(@@ (web server http) http-close))
|
(@@ (web server http) http-close))
|
||||||
@ -97,9 +108,11 @@ requests."
|
|||||||
`(#:socket ,%http-server-socket)))
|
`(#:socket ,%http-server-socket)))
|
||||||
(const #t)))
|
(const #t)))
|
||||||
|
|
||||||
(let* ((server (make-thread server-body)))
|
(with-mutex %http-server-lock
|
||||||
;; Normally SERVER exits automatically once it has received a request.
|
(let ((server (make-thread server-body)))
|
||||||
(thunk)))
|
(wait-condition-variable %http-server-ready %http-server-lock)
|
||||||
|
;; Normally SERVER exits automatically once it has received a request.
|
||||||
|
(thunk))))
|
||||||
|
|
||||||
(define-syntax-rule (with-http-server code body ...)
|
(define-syntax-rule (with-http-server code body ...)
|
||||||
(call-with-http-server code (lambda () body ...)))
|
(call-with-http-server code (lambda () body ...)))
|
||||||
|
Loading…
Reference in New Issue
Block a user