Adding WebSocket stress test and improving fit output

original commit: 5eb8f181f6
This commit is contained in:
Jay McCarthy 2010-08-19 16:32:55 -06:00
parent 646061cf40
commit 58ec991bd1

View File

@ -0,0 +1,32 @@
#lang racket/base
(require tests/stress/stress
net/websocket
net/url
racket/async-channel)
(fit "websocket echo server"
500
(λ (n)
(define confirm (make-async-channel))
(define shutdown!
(ws-serve #:port 0
#:confirmation-channel confirm
(λ (wsc _)
(let loop ()
(define m (ws-recv wsc))
(unless (eof-object? m)
(ws-send! wsc m)
(loop))))))
(define port (async-channel-get confirm))
(define THREADS 10)
(define REQS n)
(for-each thread-wait
(for/list ([t (in-range THREADS)])
(thread
(λ ()
(define conn (ws-connect (string->url (format "ws://localhost:~a" port))))
(for ([r (in-range REQS)])
(ws-send! conn "ping")
(ws-recv conn))))))))