+USING: accessors calendar classes
+concurrency.promises destructors io io.backend.unix
+io.encodings.ascii io.sockets io.sockets.secure
+io.sockets.secure.debug io.streams.duplex io.timeouts kernel
+locals namespaces threads tools.test ;
IN: io.sockets.secure.tests
-USING: accessors kernel namespaces io io.sockets
-io.sockets.secure io.encodings.ascii io.streams.duplex
-io.backend.unix classes words destructors threads tools.test
-concurrency.promises byte-arrays locals calendar io.timeouts
-io.sockets.secure.debug ;
+QUALIFIED-WITH: concurrency.messaging qm
{ 1 0 } [ [ ] with-secure-context ] must-infer-as
{ } [ <promise> "port" set ] unit-test
-:: server-test ( quot -- )
+:: server-test ( quot -- obj/f )
[
[
"127.0.0.1" 0 <inet4> f <secure> ascii <server> [
] curry with-stream
] with-disposal
] with-test-context
- ] "SSL server test" spawn drop ;
+ ] "SSL server test" qm:spawn-linked drop qm:receive ;
+
+: ?promise-test ( mailbox -- obj )
+ 340 milliseconds ?promise-timeout ;
: client-test ( -- string )
<secure-config> [
- "127.0.0.1" "port" get ?promise <inet4> f <secure> ascii <client> drop stream-contents
+ "127.0.0.1" "port" get ?promise-test <inet4> f <secure> ascii <client> drop
+ 1 seconds
+ [ stream-contents ] with-timeout*
] with-secure-context ;
+! { } [ [ class-of name>> write "done" my-mailbox mailbox-put ] server-test ] unit-test
{ } [ [ class-of name>> write ] server-test ] unit-test
{ "secure" } [ client-test ] unit-test
[
<secure-config> [
- "localhost" "port" get ?promise <inet> f <secure> ascii
+ "localhost" "port" get ?promise-test <inet> f <secure> ascii
<client> drop dispose
] with-secure-context
] [ certificate-verify-error? ] must-fail-with
{ } [
[
[
- "127.0.0.1" "port" get ?promise
+ "127.0.0.1" "port" get ?promise-test
<inet4> ascii <client> drop &dispose 1 minutes sleep
] with-destructors
] "Silly client" spawn drop
[
1 seconds secure-socket-timeout [
<secure-config> [
- "127.0.0.1" "port" get ?promise <inet4> f <secure>
+ "127.0.0.1" "port" get ?promise-test <inet4> f <secure>
ascii <client> drop dispose
] with-secure-context
] with-variable
[
[
[
- "127.0.0.1" "port" get ?promise
+ "127.0.0.1" "port" get ?promise-test
<inet4> f <secure> ascii <client> drop &dispose 1 minutes sleep
] with-test-context
] with-destructors