|
1 | 1 | #lang racket/base |
2 | 2 |
|
3 | 3 | (require racket/path |
4 | | - racket/tcp |
5 | 4 | rackunit) |
6 | 5 |
|
7 | 6 | (provide all-e2e-tests) |
8 | 7 |
|
9 | | -(define here |
10 | | - (simplify-path |
11 | | - (build-path (syntax-source #'here) 'up))) |
12 | | - |
13 | | -(define (wait-for-local-port port) |
14 | | - (let loop ([attempts 1]) |
15 | | - (sync (system-idle-evt)) |
16 | | - (with-handlers ([exn:fail? |
17 | | - (lambda (e) |
18 | | - (if (> attempts 99) |
19 | | - (raise e) |
20 | | - (loop (add1 attempts))))]) |
21 | | - (define-values (in out) |
22 | | - (tcp-connect "127.0.0.1" port)) |
23 | | - (close-output-port out) |
24 | | - (close-input-port in)))) |
| 8 | +(define here (path-only (syntax-source #'here))) |
25 | 9 |
|
26 | 10 | (define all-e2e-tests |
27 | 11 | (make-test-suite |
28 | 12 | "e2e" |
29 | 13 |
|
30 | 14 | (for/list ([test-path (in-list (directory-list here))] |
31 | | - [port (in-naturals 9111)] |
32 | 15 | #:when (directory-exists? test-path) |
33 | 16 | #:unless (equal? #"compiled" (path->bytes test-path))) |
34 | 17 | (define server-mod-path (build-path test-path "server.rkt")) |
35 | 18 | (define tests-mod-path (build-path test-path "tests.rkt")) |
36 | | - (define stopper #f) |
| 19 | + (define stop-box (box void)) |
| 20 | + (define port-box (box #f)) |
37 | 21 | (make-test-suite |
38 | 22 | (path->string (file-name-from-path test-path)) |
39 | 23 | #:before |
40 | | - (lambda _ |
41 | | - (define start |
42 | | - (dynamic-require server-mod-path 'start)) |
43 | | - |
44 | | - (set! stopper (start port)) |
45 | | - (wait-for-local-port port)) |
| 24 | + (lambda () |
| 25 | + (define start (dynamic-require server-mod-path 'start)) |
| 26 | + (let-values ([(stop port) (start)]) |
| 27 | + (set-box! stop-box stop) |
| 28 | + (set-box! port-box port))) |
46 | 29 | #:after |
47 | | - (lambda _ |
48 | | - (stopper)) |
49 | | - |
| 30 | + (lambda () |
| 31 | + ((unbox stop-box))) |
50 | 32 | (let ([make-tests (dynamic-require tests-mod-path 'make-tests)]) |
51 | | - (list (make-tests port))))))) |
| 33 | + (list |
| 34 | + (make-tests |
| 35 | + (λ () (unbox port-box)) |
| 36 | + (λ () (unbox stop-box))))))))) |
52 | 37 |
|
53 | 38 | (module+ test |
54 | 39 | (require rackunit/text-ui) |
|
0 commit comments