test-project-port: connect to server to verify that it's up

pull/244/head
Bogdan Popa 4 years ago
parent b8000c08c0
commit e7be028dc0
No known key found for this signature in database
GPG Key ID: 4227ABAD6F9D03D5

@ -1,36 +1,51 @@
#lang racket/base #lang racket/base
(require rackunit (require racket/port
racket/port racket/runtime-path
racket/runtime-path) racket/tcp
rackunit)
(define-runtime-path project-port-dir "data/project-port") (define-runtime-path project-port-dir "data/project-port")
(define thd #f) (define the-port
(define-values (in out) (make-pipe)) (dynamic-require
(parameterize ([exit-handler (lambda (code) `(submod ,(build-path project-port-dir "pollen.rkt") setup)
(fail (format "abnormal exit from raco command~n code: ~a" code)) 'project-server-port))
(kill-thread thd))])
(set! thd (define-values (in out)
(make-pipe))
(define thd
(parameterize ([current-output-port out] (parameterize ([current-output-port out]
[current-error-port out] [current-error-port out]
[current-directory project-port-dir] [current-directory project-port-dir]
[current-command-line-arguments (vector "start")]) [current-command-line-arguments (vector "start")]
[exit-handler (lambda (code)
(fail (format "abnormal exit from raco command~n code: ~a" code))
(kill-thread thd))])
(thread (thread
(lambda () (lambda ()
(dynamic-require '(submod pollen/private/command raco) #f))))) (dynamic-require '(submod pollen/private/command raco) #f)))))
(dynamic-wind (dynamic-wind
void void
(lambda () (lambda ()
(sync (sync
(handle-evt (handle-evt
(regexp-match-evt #rx"project server is http://localhost:9876" in) (regexp-match-evt #rx"ready to rock" in)
void) void)
(handle-evt (handle-evt
(alarm-evt (+ (current-inexact-milliseconds) 5000)) (alarm-evt (+ (current-inexact-milliseconds) 5000))
(lambda (_) (lambda (_)
(fail "timed out while waiting for server to start"))))) (fail "timed out while waiting for server to start"))))
(with-handlers ([exn:fail?
(lambda (e)
(fail (format "failed to connect to server: ~a" (exn-message e))))])
(define-values (cin cout)
(tcp-connect "127.0.0.1" the-port))
(close-output-port cout)
(close-input-port cin)))
(lambda () (lambda ()
(break-thread thd) (break-thread thd)
(thread-wait thd)))) (thread-wait thd)))

Loading…
Cancel
Save