Fixed various assertions.
Improved autotests Added target 'server' to be able to run the server outside the test process.
This commit is contained in:
@@ -151,7 +151,7 @@ feature {NONE} -- Parser
|
||||
end
|
||||
end
|
||||
ensure
|
||||
attached last_chunk as l_last_chunk implies l_last_chunk.count = chunk_upper - chunk_lower
|
||||
attached last_chunk as l_last_chunk implies l_last_chunk.count = chunk_upper - chunk_lower + 1
|
||||
end
|
||||
|
||||
read_chunk_data
|
||||
|
||||
59
library/server/wsf/tests/server/test.e
Normal file
59
library/server/wsf/tests/server/test.e
Normal file
@@ -0,0 +1,59 @@
|
||||
class
|
||||
TEST
|
||||
|
||||
inherit
|
||||
WSF_DEFAULT_SERVICE
|
||||
|
||||
TEST_SERVICE
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Initialize `Current'.
|
||||
do
|
||||
print ("Test Server that could be used for autotest%N")
|
||||
-- base_url := "/test/"
|
||||
|
||||
set_service_option ("port", 9091)
|
||||
set_service_option ("verbose", True)
|
||||
make_and_launch
|
||||
end
|
||||
|
||||
feature -- Helper
|
||||
|
||||
server_log_path: STRING
|
||||
local
|
||||
fn: FILE_NAME
|
||||
once
|
||||
create fn.make_from_string ("server_test.log")
|
||||
Result := fn.string
|
||||
end
|
||||
|
||||
server_log (m: STRING_8)
|
||||
local
|
||||
f: RAW_FILE
|
||||
do
|
||||
create f.make (server_log_path)
|
||||
f.open_append
|
||||
f.put_string (m)
|
||||
f.put_character ('%N')
|
||||
f.close
|
||||
end
|
||||
|
||||
base_url: detachable STRING
|
||||
|
||||
test_url (a_query_url: READABLE_STRING_8): READABLE_STRING_8
|
||||
local
|
||||
b: like base_url
|
||||
do
|
||||
b := base_url
|
||||
if b = Void then
|
||||
b := ""
|
||||
end
|
||||
Result := "/" + b + a_query_url
|
||||
end
|
||||
|
||||
end
|
||||
191
library/server/wsf/tests/server/test_service.e
Normal file
191
library/server/wsf/tests/server/test_service.e
Normal file
@@ -0,0 +1,191 @@
|
||||
note
|
||||
description: "Summary description for {}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
TEST_SERVICE
|
||||
|
||||
inherit
|
||||
WSF_SERVICE
|
||||
|
||||
feature -- Execution
|
||||
|
||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
q: detachable STRING_32
|
||||
n: NATURAL_64
|
||||
page: WSF_PAGE_RESPONSE
|
||||
log_res: WSF_LOGGER_RESPONSE_WRAPPER
|
||||
do
|
||||
debug
|
||||
server_log (req.request_uri)
|
||||
if attached req.content_type as l_content_type then
|
||||
server_log ("content_type:" + l_content_type.string)
|
||||
end
|
||||
end
|
||||
if attached req.http_expect as l_expect and then l_expect.same_string ("100-continue") then
|
||||
(create {EXECUTION_ENVIRONMENT}).sleep (900_000_000) -- 900 milliseconds
|
||||
end
|
||||
|
||||
create page.make
|
||||
if attached req.request_uri as l_uri then
|
||||
if l_uri.starts_with (test_url ("get/01")) then
|
||||
page.set_status_code (200)
|
||||
page.header.put_content_type_text_plain
|
||||
page.put_string ("get-01")
|
||||
create q.make_empty
|
||||
|
||||
across
|
||||
req.query_parameters as qcur
|
||||
loop
|
||||
if not q.is_empty then
|
||||
q.append_character ('&')
|
||||
end
|
||||
q.append (qcur.item.name.as_string_32 + "=" + qcur.item.string_representation)
|
||||
end
|
||||
if not q.is_empty then
|
||||
page.put_string ("(" + q + ")")
|
||||
end
|
||||
elseif l_uri.starts_with (test_url ("post/01")) then
|
||||
page.put_header (200, <<["Content-Type", "text/plain"]>>)
|
||||
page.put_string ("post-01")
|
||||
create q.make_empty
|
||||
|
||||
across
|
||||
req.query_parameters as qcur
|
||||
loop
|
||||
if not q.is_empty then
|
||||
q.append_character ('&')
|
||||
end
|
||||
q.append (qcur.item.name.as_string_32 + "=" + qcur.item.string_representation)
|
||||
end
|
||||
|
||||
if not q.is_empty then
|
||||
page.put_string ("(" + q + ")")
|
||||
end
|
||||
|
||||
create q.make_empty
|
||||
-- req.set_raw_input_data_recorded (True)
|
||||
|
||||
across
|
||||
req.form_parameters as fcur
|
||||
loop
|
||||
debug
|
||||
server_log ("%Tform: " + fcur.item.name)
|
||||
end
|
||||
if not q.is_empty then
|
||||
q.append_character ('&')
|
||||
end
|
||||
q.append (fcur.item.name.as_string_32 + "=" + fcur.item.string_representation)
|
||||
end
|
||||
|
||||
-- if attached req.raw_input_data as d then
|
||||
-- server_log ("Raw data=" + d)
|
||||
-- end
|
||||
|
||||
if not q.is_empty then
|
||||
page.put_string (" : " + q )
|
||||
end
|
||||
elseif l_uri.starts_with (test_url ("post/file/01")) then
|
||||
page.put_header (200, <<["Content-Type", "text/plain"]>>)
|
||||
page.put_string ("post-file-01")
|
||||
n := req.content_length_value
|
||||
if n > 0 then
|
||||
req.input.read_string (n.to_integer_32)
|
||||
q := req.input.last_string
|
||||
page.put_string ("%N" + q)
|
||||
end
|
||||
else
|
||||
page.put_header (200, <<["Content-Type", "text/plain"]>>)
|
||||
page.put_string ("Hello")
|
||||
end
|
||||
else
|
||||
page.put_header (200, <<["Content-Type", "text/plain"]>>)
|
||||
page.put_string ("Bye")
|
||||
end
|
||||
|
||||
if
|
||||
attached new_file (req, "output.log") as l_out and
|
||||
attached new_file (req, "error.log") as l_err
|
||||
then
|
||||
create log_res.make_from_response (res, l_out, l_err)
|
||||
log_res.send (page)
|
||||
|
||||
l_out.close
|
||||
l_err.close
|
||||
else
|
||||
check False end
|
||||
res.send (page)
|
||||
end
|
||||
end
|
||||
|
||||
new_file (req: WSF_REQUEST; a_suffix: STRING): detachable FILE
|
||||
local
|
||||
dp, p, fp: FILE_NAME
|
||||
d: DIRECTORY
|
||||
i: INTEGER
|
||||
f: detachable FILE
|
||||
retried: INTEGER
|
||||
do
|
||||
if retried = 0 then
|
||||
create dp.make_from_string ("logs")
|
||||
create d.make (dp.string)
|
||||
if not d.exists then
|
||||
d.recursive_create_dir
|
||||
end
|
||||
if attached req.request_time_stamp as t then
|
||||
create p.make_from_string (t.out)
|
||||
else
|
||||
create p.make_from_string ("")
|
||||
end
|
||||
|
||||
from
|
||||
i := 0
|
||||
create fp.make_from_string (dp.string)
|
||||
if p.is_empty then
|
||||
fp.set_file_name (p.string + a_suffix)
|
||||
else
|
||||
fp.set_file_name (p.string + "-" + a_suffix)
|
||||
end
|
||||
create {PLAIN_TEXT_FILE} f.make (fp.string)
|
||||
until
|
||||
not f.exists
|
||||
loop
|
||||
i := i + 1
|
||||
create fp.make_from_string (dp.string)
|
||||
if p.is_empty then
|
||||
fp.set_file_name (p.string + i.out + "-" + a_suffix)
|
||||
else
|
||||
fp.set_file_name (p.string + "_" + i.out + "-" + a_suffix)
|
||||
end
|
||||
|
||||
f.make (fp.string)
|
||||
end
|
||||
f.open_write
|
||||
elseif retried < 5 then
|
||||
|
||||
-- Eventually another request created the file at the same time ..
|
||||
f := new_file (req, a_suffix)
|
||||
else
|
||||
f := Void
|
||||
end
|
||||
Result := f
|
||||
rescue
|
||||
retried := retried + 1
|
||||
retry
|
||||
end
|
||||
|
||||
feature -- Helper
|
||||
|
||||
server_log (s: STRING)
|
||||
deferred
|
||||
end
|
||||
|
||||
test_url (a_query_url: READABLE_STRING_8): READABLE_STRING_8
|
||||
deferred
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ inherit
|
||||
on_clean
|
||||
end
|
||||
|
||||
WSF_SERVICE
|
||||
TEST_SERVICE
|
||||
undefine
|
||||
default_create
|
||||
end
|
||||
@@ -36,19 +36,26 @@ feature {NONE} -- Events
|
||||
wt: WORKER_THREAD
|
||||
e: EXECUTION_ENVIRONMENT
|
||||
do
|
||||
-- port_number := 9091
|
||||
create e
|
||||
-- port_number := 9091 -- Uncomment to use with server outside this process
|
||||
if port_number = 0 then
|
||||
server_log ("== Current directory: " + e.current_working_directory)
|
||||
|
||||
port_number := 0
|
||||
base_url := "test/"
|
||||
base_url := "/test/"
|
||||
create app.make_custom (to_wgi_service, base_url)
|
||||
web_app := app
|
||||
|
||||
create wt.make (agent app.listen (port_number))
|
||||
wt.launch
|
||||
|
||||
create e
|
||||
e.sleep (1_000_000_000 * 5)
|
||||
|
||||
port_number := app.port
|
||||
server_log ("Server port=" + port_number.out)
|
||||
else
|
||||
server_log ("Use existing server")
|
||||
server_log ("== Current directory: " + e.current_working_directory)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
server_log_name: STRING
|
||||
@@ -74,99 +81,6 @@ feature {NONE} -- Events
|
||||
f.close
|
||||
end
|
||||
|
||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
q: detachable STRING_32
|
||||
n: NATURAL_64
|
||||
page: WSF_PAGE_RESPONSE
|
||||
do
|
||||
debug
|
||||
server_log (req.request_uri)
|
||||
if attached req.content_type as l_content_type then
|
||||
server_log ("content_type:" + l_content_type.string)
|
||||
end
|
||||
end
|
||||
|
||||
create page.make
|
||||
if attached req.request_uri as l_uri then
|
||||
if l_uri.starts_with (test_url ("get/01")) then
|
||||
page.set_status_code (200)
|
||||
page.header.put_content_type_text_plain
|
||||
page.put_string ("get-01")
|
||||
create q.make_empty
|
||||
|
||||
across
|
||||
req.query_parameters as qcur
|
||||
loop
|
||||
if not q.is_empty then
|
||||
q.append_character ('&')
|
||||
end
|
||||
q.append (qcur.item.name.as_string_32 + "=" + qcur.item.string_representation)
|
||||
end
|
||||
if not q.is_empty then
|
||||
page.put_string ("(" + q + ")")
|
||||
end
|
||||
elseif l_uri.starts_with (test_url ("post/01")) then
|
||||
page.put_header (200, <<["Content-Type", "text/plain"]>>)
|
||||
page.put_string ("post-01")
|
||||
create q.make_empty
|
||||
|
||||
across
|
||||
req.query_parameters as qcur
|
||||
loop
|
||||
if not q.is_empty then
|
||||
q.append_character ('&')
|
||||
end
|
||||
q.append (qcur.item.name.as_string_32 + "=" + qcur.item.string_representation)
|
||||
end
|
||||
|
||||
if not q.is_empty then
|
||||
page.put_string ("(" + q + ")")
|
||||
end
|
||||
|
||||
create q.make_empty
|
||||
-- req.set_raw_input_data_recorded (True)
|
||||
|
||||
across
|
||||
req.form_parameters as fcur
|
||||
loop
|
||||
debug
|
||||
server_log ("%Tform: " + fcur.item.name)
|
||||
end
|
||||
if not q.is_empty then
|
||||
q.append_character ('&')
|
||||
end
|
||||
q.append (fcur.item.name.as_string_32 + "=" + fcur.item.string_representation)
|
||||
end
|
||||
|
||||
-- if attached req.raw_input_data as d then
|
||||
-- server_log ("Raw data=" + d)
|
||||
-- end
|
||||
|
||||
if not q.is_empty then
|
||||
page.put_string (" : " + q )
|
||||
end
|
||||
elseif l_uri.starts_with (test_url ("post/file/01")) then
|
||||
page.put_header (200, <<["Content-Type", "text/plain"]>>)
|
||||
page.put_string ("post-file-01")
|
||||
n := req.content_length_value
|
||||
if n > 0 then
|
||||
req.input.read_string (n.to_integer_32)
|
||||
q := req.input.last_string
|
||||
page.put_string ("%N" + q)
|
||||
end
|
||||
else
|
||||
page.put_header (200, <<["Content-Type", "text/plain"]>>)
|
||||
page.put_string ("Hello")
|
||||
end
|
||||
else
|
||||
page.put_header (200, <<["Content-Type", "text/plain"]>>)
|
||||
page.put_string ("Bye")
|
||||
end
|
||||
|
||||
res.send (page)
|
||||
end
|
||||
|
||||
test_url (a_query_url: READABLE_STRING_8): READABLE_STRING_8
|
||||
local
|
||||
b: like base_url
|
||||
@@ -175,7 +89,7 @@ feature {NONE} -- Events
|
||||
if b = Void then
|
||||
b := ""
|
||||
end
|
||||
Result := "/" + b + a_query_url
|
||||
Result := b + a_query_url
|
||||
end
|
||||
|
||||
on_clean
|
||||
|
||||
@@ -23,7 +23,7 @@ feature {NONE} -- Helpers
|
||||
adapted_context (ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_REQUEST_CONTEXT
|
||||
do
|
||||
Result := Precursor (ctx)
|
||||
Result.headers.extend ("chunked", "Transfer-Encoding")
|
||||
Result.headers.force ("chunked", "Transfer-Encoding")
|
||||
end
|
||||
|
||||
feature -- Test routines
|
||||
|
||||
@@ -1,25 +1,37 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-9-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-9-0 http://www.eiffel.com/developers/xml/configuration-1-9-0.xsd" name="wsf_tests" uuid="C4FF9CDA-B4E4-4841-97E0-7F799B85B657">
|
||||
<target name="tests">
|
||||
<root class="ANY" feature="default_create"/>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-10-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-10-0 http://www.eiffel.com/developers/xml/configuration-1-10-0.xsd" name="wsf_tests" uuid="C4FF9CDA-B4E4-4841-97E0-7F799B85B657">
|
||||
<target name="server">
|
||||
<root class="TEST" feature="make"/>
|
||||
<file_rule>
|
||||
<exclude>/.git$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
<exclude>/.svn$</exclude>
|
||||
</file_rule>
|
||||
<option debug="true" warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="provisional">
|
||||
<assertions precondition="true" postcondition="true" check="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="connector_nino" location="..\..\ewsgi\connectors\nino\nino-safe.ecf" readonly="false"/>
|
||||
<library name="connector_null" location="..\..\ewsgi\connectors\null\null-safe.ecf" readonly="false"/>
|
||||
<library name="dft_nino" location="..\default\nino-safe.ecf"/>
|
||||
<library name="ewsgi" location="..\..\ewsgi\ewsgi-safe.ecf" readonly="false"/>
|
||||
<library name="http" location="../../../network/protocol/http/http-safe.ecf" readonly="false"/>
|
||||
<library name="http_client" location="../../../network/http_client/http_client-safe.ecf" readonly="false"/>
|
||||
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
|
||||
<library name="ewsgi" location="..\..\ewsgi\ewsgi-safe.ecf" readonly="false">
|
||||
<option>
|
||||
<assertions precondition="true" postcondition="true" check="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
</library>
|
||||
<library name="http" location="..\..\..\network\protocol\http\http-safe.ecf" readonly="false"/>
|
||||
<library name="http_client" location="..\..\..\network\http_client\http_client-safe.ecf" readonly="false"/>
|
||||
<library name="thread" location="$ISE_LIBRARY\library\thread\thread-safe.ecf"/>
|
||||
<library name="wsf" location="..\wsf-safe.ecf" readonly="false"/>
|
||||
<library name="wsf" location="..\wsf-safe.ecf" readonly="false">
|
||||
<option>
|
||||
<assertions precondition="true" postcondition="true" check="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
</library>
|
||||
<cluster name="server" location=".\server\" recursive="true"/>
|
||||
</target>
|
||||
<target name="wsf_tests" extends="server">
|
||||
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
|
||||
<tests name="src" location=".\src\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-9-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-9-0 http://www.eiffel.com/developers/xml/configuration-1-9-0.xsd" name="wsf_tests" uuid="C4FF9CDA-B4E4-4841-97E0-7F799B85B657">
|
||||
<target name="tests">
|
||||
<root class="ANY" feature="default_create"/>
|
||||
<target name="server">
|
||||
<root class="TEST" feature="make"/>
|
||||
<file_rule>
|
||||
<exclude>/.git$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
@@ -14,12 +14,16 @@
|
||||
<library name="connector_nino" location="..\..\ewsgi\connectors\nino\nino.ecf" readonly="false"/>
|
||||
<library name="connector_null" location="..\..\ewsgi\connectors\null\null.ecf" readonly="false"/>
|
||||
<library name="dft_nino" location="..\default\nino.ecf"/>
|
||||
<library name="ewsgi" location="..\..\ewsgi\ewsgi.ecf"/>
|
||||
<library name="http_client" location="../../../network/http_client/http_client.ecf"/>
|
||||
<library name="testing" location="$ISE_LIBRARY\library\testing\testing.ecf"/>
|
||||
<library name="ewsgi" location="..\..\ewsgi\ewsgi.ecf" readonly="false"/>
|
||||
<library name="http" location="..\..\..\network\protocol\http\http.ecf" readonly="false"/>
|
||||
<library name="http_client" location="..\..\..\network\http_client\http_client.ecf" readonly="false"/>
|
||||
<library name="thread" location="$ISE_LIBRARY\library\thread\thread.ecf"/>
|
||||
<library name="http" location="../../../network/protocol/http/http.ecf" readonly="false"/>
|
||||
<library name="wsf" location="..\wsf.ecf" readonly="false"/>
|
||||
<cluster name="server" location=".\server\" recursive="true"/>
|
||||
</target>
|
||||
<target name="wsf_tests" extends="server">
|
||||
<library name="testing" location="$ISE_LIBRARY\library\testing\testing.ecf"/>
|
||||
<tests name="src" location=".\src\" recursive="true"/>
|
||||
</target>
|
||||
|
||||
</system>
|
||||
|
||||
Reference in New Issue
Block a user