diff --git a/basis/http/http-tests.factor b/basis/http/http-tests.factor index b3930878ff..96320b7d12 100644 --- a/basis/http/http-tests.factor +++ b/basis/http/http-tests.factor @@ -192,110 +192,104 @@ test-db [ init-furnace-tables ] with-db -: test-httpd ( -- ) - #! Return as soon as server is running. - - 1237 >>insecure - f >>secure - start-server* ; +: test-httpd ( responder -- ) + [ + main-responder set + + 0 >>insecure + f >>secure + dup start-server* + sockets>> first addr>> port>> + ] with-scope "port" set ; [ ] [ - [ + + add-quit-action - add-quit-action - - "resource:basis/http/test" >>default - "nested" add-responder - - [ URL" redirect-loop" ] >>display - "redirect-loop" add-responder - main-responder set + "resource:basis/http/test" >>default + "nested" add-responder + + [ URL" redirect-loop" ] >>display + "redirect-loop" add-responder - test-httpd - ] with-scope + test-httpd ] unit-test +: add-port ( url -- url' ) + >url clone "port" get >>port ; + [ t ] [ "resource:basis/http/test/foo.html" ascii file-contents - "http://localhost:1237/nested/foo.html" http-get nip = + "http://localhost/nested/foo.html" add-port http-get nip = ] unit-test -[ "http://localhost:1237/redirect-loop" http-get nip ] +[ "http://localhost/redirect-loop" add-port http-get nip ] [ too-many-redirects? ] must-fail-with [ "Goodbye" ] [ - "http://localhost:1237/quit" http-get nip + "http://localhost/quit" add-port http-get nip ] unit-test ! HTTP client redirect bug [ ] [ - [ - - add-quit-action - [ "quit" ] >>display - "redirect" add-responder - main-responder set + + add-quit-action + [ "quit" ] >>display + "redirect" add-responder - test-httpd - ] with-scope + test-httpd ] unit-test [ "Goodbye" ] [ - "http://localhost:1237/redirect" http-get nip + "http://localhost/redirect" add-port http-get nip ] unit-test [ ] [ - [ "http://localhost:1237/quit" http-get 2drop ] ignore-errors + [ "http://localhost/quit" add-port http-get 2drop ] ignore-errors ] unit-test ! Dispatcher bugs [ ] [ - [ + + + "Test" + + "" add-responder + add-quit-action - - "Test" - - "" add-responder - add-quit-action - - "" add-responder - "d" add-responder - test-db - main-responder set + "" add-responder + "d" add-responder + test-db - test-httpd - ] with-scope + test-httpd ] unit-test : 404? [ download-failed? ] [ response>> code>> 404 = ] bi and ; ! This should give a 404 not an infinite redirect loop -[ "http://localhost:1237/d/blah" http-get nip ] [ 404? ] must-fail-with +[ "http://localhost/d/blah" add-port http-get nip ] [ 404? ] must-fail-with ! This should give a 404 not an infinite redirect loop -[ "http://localhost:1237/blah/" http-get nip ] [ 404? ] must-fail-with +[ "http://localhost/blah/" add-port http-get nip ] [ 404? ] must-fail-with -[ "Goodbye" ] [ "http://localhost:1237/quit" http-get nip ] unit-test +[ "Goodbye" ] [ "http://localhost/quit" add-port http-get nip ] unit-test [ ] [ - [ - - [ [ "Hi" write ] "text/plain" ] >>display - "Test" - - "" add-responder - add-quit-action - test-db - main-responder set + + [ [ "Hi" write ] "text/plain" ] >>display + "Test" + + "" add-responder + add-quit-action + test-db - test-httpd - ] with-scope + test-httpd ] unit-test -[ "Hi" ] [ "http://localhost:1237/" http-get nip ] unit-test +[ "Hi" ] [ "http://localhost/" add-port http-get nip ] unit-test -[ "Goodbye" ] [ "http://localhost:1237/quit" http-get nip ] unit-test +[ "Goodbye" ] [ "http://localhost/quit" add-port http-get nip ] unit-test USING: html.components html.elements html.forms xml xml.utilities validators @@ -304,22 +298,19 @@ furnace furnace.conversations ; SYMBOL: a [ ] [ - [ - - - [ a get-global "a" set-value ] >>init - [ [ "a" render ] "text/html" ] >>display - [ { { "a" [ v-integer ] } } validate-params ] >>validate - [ "a" value a set-global URL" " ] >>submit - - - >>default - add-quit-action - test-db - main-responder set + + + [ a get-global "a" set-value ] >>init + [ [ "a" render ] "text/html" ] >>display + [ { { "a" [ v-integer ] } } validate-params ] >>validate + [ "a" value a set-global URL" " ] >>submit + + + >>default + add-quit-action + test-db - test-httpd - ] with-scope + test-httpd ] unit-test 3 a set-global @@ -327,27 +318,35 @@ SYMBOL: a : test-a string>xml "input" tag-named "value" swap at ; [ "3" ] [ - "http://localhost:1237/" http-get + "http://localhost/" add-port http-get swap dup cookies>> "cookies" set session-id-key get-cookie value>> "session-id" set test-a ] unit-test [ "4" ] [ - H{ { "a" "4" } { "__u" "http://localhost:1237/" } } "session-id" get session-id-key associate assoc-union - "http://localhost:1237/" "cookies" get >>cookies http-request nip test-a + [ + "4" "a" set + "http://localhost" add-port "__u" set + "session-id" get session-id-key set + ] H{ } make-assoc + "http://localhost/" add-port "cookies" get >>cookies http-request nip test-a ] unit-test [ 4 ] [ a get-global ] unit-test ! Test flash scope [ "xyz" ] [ - H{ { "a" "xyz" } { "__u" "http://localhost:1237/" } } "session-id" get session-id-key associate assoc-union - "http://localhost:1237/" "cookies" get >>cookies http-request nip test-a + [ + "xyz" "a" set + "http://localhost" add-port "__u" set + "session-id" get session-id-key set + ] H{ } make-assoc + "http://localhost/" add-port "cookies" get >>cookies http-request nip test-a ] unit-test [ 4 ] [ a get-global ] unit-test -[ "Goodbye" ] [ "http://localhost:1237/quit" http-get nip ] unit-test +[ "Goodbye" ] [ "http://localhost/quit" add-port http-get nip ] unit-test ! Test cloning [ f ] [ <404> dup clone "b" "a" set-header drop "a" header ] unit-test diff --git a/basis/io/servers/connection/connection-tests.factor b/basis/io/servers/connection/connection-tests.factor index a3223ed2aa..ae79290f0a 100644 --- a/basis/io/servers/connection/connection-tests.factor +++ b/basis/io/servers/connection/connection-tests.factor @@ -27,25 +27,12 @@ concurrency.promises io.encodings.ascii io threads calendar ; init-server semaphore>> count>> ] unit-test -[ ] [ "p" set ] unit-test - [ ] [ 5 >>max-connections - 1237 >>insecure + 0 >>insecure [ "Hello world." write stop-this-server ] >>handler - "server" set + dup start-server* sockets>> first addr>> port>> "port" set ] unit-test -[ ] [ - [ - "server" get start-server - t "p" get fulfill - ] in-thread -] unit-test - -[ ] [ "server" get wait-for-server ] unit-test - -[ "Hello world." ] [ "localhost" 1237 ascii drop contents ] unit-test - -[ t ] [ "p" get 2 seconds ?promise-timeout ] unit-test +[ "Hello world." ] [ "localhost" "port" get ascii drop contents ] unit-test diff --git a/basis/tools/deploy/deploy-tests.factor b/basis/tools/deploy/deploy-tests.factor index db4255cdb1..71e83ea29c 100644 --- a/basis/tools/deploy/deploy-tests.factor +++ b/basis/tools/deploy/deploy-tests.factor @@ -1,7 +1,8 @@ IN: tools.deploy.tests USING: tools.test system io.files kernel tools.deploy.config tools.deploy.backend math sequences io.launcher arrays -namespaces continuations layouts accessors ; +namespaces continuations layouts accessors io.encodings.ascii +urls math.parser ; : shake-and-bake ( vocab -- ) [ "test.image" temp-file delete-file ] ignore-errors @@ -38,7 +39,7 @@ namespaces continuations layouts accessors ; ! [ ] [ "tetris" shake-and-bake ] unit-test ! ! [ t ] [ 1500000 small-enough? ] unit-test -! + [ ] [ "bunny" shake-and-bake ] unit-test [ t ] [ 2500000 small-enough? ] unit-test @@ -71,22 +72,24 @@ M: quit-responder call-responder* : add-quot-responder ( responder -- responder ) quit-responder "quit" add-responder ; -: test-httpd ( -- ) - #! Return as soon as server is running. - - 1237 >>insecure - f >>secure - start-server* ; +: test-httpd ( responder -- ) + [ + main-responder set + + 0 >>insecure + f >>secure + dup start-server* + sockets>> first addr>> port>> + dup number>string "resource:temp/port-number" ascii set-file-contents + ] with-scope + "port" set ; [ ] [ - [ - - add-quot-responder - "resource:basis/http/test" >>default - main-responder set + + add-quot-responder + "resource:basis/http/test" >>default - test-httpd - ] with-scope + test-httpd ] unit-test [ ] [ @@ -94,7 +97,10 @@ M: quit-responder call-responder* run-temp-image ] unit-test -[ ] [ "http://localhost:1237/quit" http-get 2drop ] unit-test +: add-port ( url -- url' ) + >url clone "port" get >>port ; + +[ ] [ "http://localhost/quit" add-port http-get 2drop ] unit-test [ ] [ "tools.deploy.test.6" shake-and-bake diff --git a/basis/tools/deploy/test/5/5.factor b/basis/tools/deploy/test/5/5.factor index debc020d49..9118fa3ca7 100644 --- a/basis/tools/deploy/test/5/5.factor +++ b/basis/tools/deploy/test/5/5.factor @@ -1,7 +1,10 @@ IN: tools.deploy.test.5 -USING: http.client kernel ; +USING: accessors urls io.encodings.ascii io.files math.parser +http.client kernel ; : deploy-test-5 ( -- ) - "http://localhost:1237/foo.html" http-get 2drop ; + URL" http://localhost/foo.html" clone + "resource:port-number" ascii file-contents string>number >>port + http-get 2drop ; MAIN: deploy-test-5