Correct test usage of port
This commit is contained in:
parent
9b657ad53a
commit
6a43e379e1
|
@ -5,9 +5,10 @@
|
|||
web-server/servlet-env
|
||||
tests/eli-tester)
|
||||
|
||||
(define PORT 8999)
|
||||
|
||||
(define (do-the-test PORT #:connection-close? connection-close?)
|
||||
(define (do-the-test #:connection-close? connection-close?)
|
||||
(define cust (make-custodian))
|
||||
(begin0
|
||||
(parameterize ([current-custodian cust])
|
||||
(define tc (make-thread-cell 0))
|
||||
|
||||
(define (start req)
|
||||
|
@ -26,22 +27,26 @@
|
|||
#:connection-close? connection-close?
|
||||
#:quit? #f
|
||||
#:listen-ip #f
|
||||
#:port PORT
|
||||
#:port 0
|
||||
#:servlet-path "/")))))
|
||||
|
||||
; Wait for server to start
|
||||
(void (read-line pipe-read-p)
|
||||
(read-line pipe-read-p))
|
||||
(define port-embedded-line (read-line pipe-read-p))
|
||||
(match-define (regexp #rx"Your Web application is running at http://localhost:([0-9]+)\\."
|
||||
(list _ port-string))
|
||||
port-embedded-line)
|
||||
(define port (string->number port-string))
|
||||
(void (read-line pipe-read-p))
|
||||
|
||||
(define-values (http-read-p http-write-p)
|
||||
(tcp-connect "localhost" PORT))
|
||||
(tcp-connect "localhost" port))
|
||||
|
||||
(define (get-tc/err http-read-p http-write-p)
|
||||
(with-handlers
|
||||
([exn?
|
||||
(λ (x)
|
||||
(define-values (new-http-read-p new-http-write-p)
|
||||
(tcp-connect "localhost" PORT))
|
||||
(tcp-connect "localhost" port))
|
||||
(set! http-read-p new-http-read-p)
|
||||
(set! http-write-p new-http-write-p)
|
||||
(get-tc http-read-p http-write-p))])
|
||||
|
@ -60,7 +65,9 @@
|
|||
(get-tc/err http-read-p http-write-p))
|
||||
|
||||
(kill-thread server-t)))
|
||||
(custodian-shutdown-all cust)))
|
||||
|
||||
(test
|
||||
(do-the-test #:connection-close? #f) => (list 1 2)
|
||||
(do-the-test #:connection-close? #t) => (list 1 1))
|
||||
|
||||
(test
|
||||
(do-the-test PORT #:connection-close? #f) => (list 1 2)
|
||||
(do-the-test (add1 PORT) #:connection-close? #t) => (list 1 1))
|
||||
|
|
Loading…
Reference in New Issue
Block a user