Skip to content

Commit 4b2e41b

Browse files
committed
test,serve: adjust kill test to pass in ci
1 parent dd0781e commit 4b2e41b

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ jobs:
55
name: "Build on Racket '${{ matrix.racket-version }}' (${{ matrix.racket-variant }})"
66
runs-on: ubuntu-latest
77
strategy:
8+
fail-fast: false
89
matrix:
910
racket-version: ["8.0", "8.1", "current"]
1011
racket-variant: ["BC", "CS"]

web-server-test/tests/web-server/serve-tests.rkt

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
racket/port
66
racket/promise
77
rackunit
8+
version/utils
89
web-server/http
910
web-server/safety-limits
1011
web-server/servlet-dispatch
@@ -107,36 +108,48 @@
107108
(http-conn-close! hc)))
108109
(check-duration stop 1 3 5))))
109110

110-
(test-case "kills the server if stop is called twice"
111-
(define started?-sema
112-
(make-semaphore))
113-
(call-with-web-server
114-
(lambda (_req)
115-
(response/output
116-
(lambda (out)
117-
(displayln "start" out)
118-
(semaphore-post started?-sema)
119-
(sleep 100)
120-
(displayln "end" out))))
121-
(lambda (port stop)
122-
(define hc (http-conn-open "127.0.0.1" #:port port))
123-
(define-values (status _headers in)
124-
(http-conn-sendrecv! hc "/"))
125-
(check-equal? status #"HTTP/1.1 200 OK")
126-
(define data-promise
127-
(delay/thread
128-
(port->bytes in)))
129-
(semaphore-wait started?-sema)
130-
(define stop-thds
131-
(for/list ([_ (in-range 2)])
132-
(thread stop)))
133-
(check-duration
134-
(lambda ()
135-
(for-each thread-wait stop-thds))
136-
0 1 2)
137-
(check-equal?
138-
(force data-promise)
139-
#"start\n")))))))
111+
;; On versions prior to [1], net/http-client writes to standard
112+
;; error when reading from the connection's input port goes wrong.
113+
;; This makes raco test fail in --drdr mode, so avoid running this
114+
;; test on versions before 8.17.0.6.
115+
;;
116+
;; [1]: https://github.com/racket/racket/pull/5296
117+
(when (version<=? "8.17.0.6" (version))
118+
(test-case "kills the server if stop is called twice"
119+
(define started?-sema
120+
(make-semaphore))
121+
(call-with-web-server
122+
(lambda (_req)
123+
(response/output
124+
(lambda (out)
125+
(displayln "start" out)
126+
(semaphore-post started?-sema)
127+
(sleep 100)
128+
(displayln "end" out))))
129+
(lambda (port stop)
130+
(define hc (http-conn-open "127.0.0.1" #:port port))
131+
(define-values (status _headers in)
132+
(http-conn-sendrecv! hc "/"))
133+
(check-equal? status #"HTTP/1.1 200 OK")
134+
(define data-promise
135+
(delay/thread
136+
(with-handlers ([(lambda (e)
137+
(and (exn:fail? e)
138+
(regexp-match? #rx"input port is closed" (exn-message e))))
139+
(lambda (_)
140+
#"")])
141+
(port->bytes in))))
142+
(semaphore-wait started?-sema)
143+
(define stop-thds
144+
(for/list ([_ (in-range 2)])
145+
(thread stop)))
146+
(check-duration
147+
(lambda ()
148+
(for-each thread-wait stop-thds))
149+
0 1 2)
150+
(check-match
151+
(force data-promise)
152+
(or #"" #"start\n")))))))))
140153

141154
(module+ test
142155
(require rackunit/text-ui)

0 commit comments

Comments
 (0)