Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Sagittarius uses CMake for its building infrastructure. If you do not
have it on your platform, please install it.

- [CMake](http://www.cmake.org/)

NOTE: It should be higher than 3.5, though we don't use new features, so
it should also work with 2.8.4

Expand All @@ -25,6 +25,7 @@ install to default location, run the following commands in the
directory where all distributed files are expanded (c.f. By default
it'd be `sagittarius-X.X.X`, `X.X.X` is the version you downloaded):

% ./dist.sh gen
% cmake .
% make
% make install
Expand Down Expand Up @@ -87,7 +88,7 @@ for example:
To run the tests, specify `test` target.

% make test

Or, alternatively, you can also use `ctest`. This is convenient to
test individual tests.

Expand Down Expand Up @@ -138,7 +139,7 @@ Only with Homebrew is tested. A user can install sagittarius directly with
homebrew, via

$ brew install sagittarius-scheme

Alternately, the user can install the following dependencies and then make
sagittarius locally.

Expand Down Expand Up @@ -226,7 +227,7 @@ of the test execution when the test failed.
% ctest --output-on-failure
```

For more options, please refer the official document of the
For more options, please refer the official document of the
[`CTest`](https://cmake.org/cmake/help/latest/manual/ctest.1.html)

# Forums and bug reporting
Expand Down
2 changes: 1 addition & 1 deletion sitelib/sagittarius/test/helper.scm
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
((show)
(lambda ()
(show))))))
)
)
31 changes: 24 additions & 7 deletions test/tests/net/server.scm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
;; multi threading server
(let ()
(define config (make-server-config :shutdown-port +shutdown-port+
:exception-handler
:exception-handler
(lambda (sr s e) (print e))
:max-thread 5
:use-ipv6? #t))
Expand Down Expand Up @@ -102,7 +102,7 @@
(let ((sock (make-client-tls-socket "localhost" (server-port server)
ai-family)))
(socket-send sock (string->utf8 "hello"))
(test-equal "TLS echo back"
(test-equal "TLS echo back"
(string->utf8 "hello") (socket-recv sock 255))
(socket-close sock))))
(server-start! server :background #t)
Expand Down Expand Up @@ -130,21 +130,30 @@
(test-equal 'context (server-context server))
(test-error (server-status server)))

;; Test for socket detachment functionality in the simple server framework.
;;
;; This test verifies that a server can detach sockets and hand them off to
;; external actors for processing, while maintaining proper thread pool status.
;; The test creates a non-blocking server that detaches incoming connections
;; to a shared-queue-channel-actor which handles the actual socket
;; communication.
(let ()
;; the thread management is done outside of our threads
;; thus there's no way to guarantee. let's hope...
(define (hope-it-works)
(thread-yield!)
(thread-sleep! 1))
;; Actor that receives detached sockets and handles them independently.
(define detached-actor
(make-shared-queue-channel-actor
(lambda (input-receiver output-sender)
(define socket (input-receiver))
(output-sender 'ready)
(hope-it-works)
(let ((msg (input-receiver)))
(socket-send socket msg))
(socket-send socket msg))
(output-sender 'done)
;; Wait for finish signal.
(input-receiver)
(socket-shutdown socket SHUT_RDWR)
(socket-close socket))))
Expand All @@ -153,7 +162,9 @@
:exception-handler print))
(define server (make-simple-server
"12345" (lambda (s sock)
;; Remove socket from server's management.
(server-detach-socket! s sock)
;; Hand it over to external actor.
(actor-send-message! detached-actor sock))
:config config))
(define (check-status server)
Expand All @@ -170,26 +181,32 @@
(test-assert
(call-with-string-output-port
(lambda (out) (report-server-status status out))))))

(server-start! server :background #t)
(test-assert (server-status server))
(check-status server)

(let ((sock (make-client-socket "localhost" "12345")))
;; Trigger socket detachment by connecting.
(socket-send sock #vu8(0))
(test-equal 'ready (actor-receive-message! detached-actor))
;; Send actual data through the detached socket.
(actor-send-message! detached-actor #vu8(1 2 3 4 5))
(test-equal 'done (actor-receive-message! detached-actor))
(hope-it-works)
;; it should have 0 active socket on the server, it's detached
;; and server socket is not closed
(check-status server)
;; Signal actor to finish and close socket.
(actor-send-message! detached-actor 'finish)
(let ((bv (socket-recv sock 5)))
(test-equal #vu8(1 2 3 4 5) bv))
;; Handle potential race condition where socket closes before read.
(guard (e ((socket-error? e) (test-assert "server socket closed" #t))
(else (test-assert (condition-message e) #f)))
(let ((bv (socket-recv sock 5)))
(test-equal #vu8(1 2 3 4 5) bv)))
(socket-shutdown sock SHUT_RDWR)
(socket-close sock))

(server-stop! server))

(test-end)