ci: fix failing vweb test, increase timeout for vweb_test_server.v, add VWEB_LOGFILE

pull/7811/head
Delyan Angelov 2021-01-02 13:21:30 +02:00
parent 01e098aa77
commit d912ff165b
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 16 additions and 7 deletions

View File

@ -7,8 +7,9 @@ import io
const ( const (
sport = 12380 sport = 12380
exit_after_time = 5000 // milliseconds exit_after_time = 7000 // milliseconds
vexe = os.getenv('VEXE') vexe = os.getenv('VEXE')
vweb_logfile = os.getenv('VWEB_LOGFILE')
vroot = os.dir(vexe) vroot = os.dir(vexe)
serverexe = os.join_path(os.cache_dir(), 'vweb_test_server.exe') serverexe = os.join_path(os.cache_dir(), 'vweb_test_server.exe')
tcp_r_timeout = 30 * time.second tcp_r_timeout = 30 * time.second
@ -30,7 +31,13 @@ fn test_a_simple_vweb_app_can_be_compiled() {
} }
fn test_a_simple_vweb_app_runs_in_the_background() { fn test_a_simple_vweb_app_runs_in_the_background() {
suffix := $if windows { '' } $else { ' > /dev/null &' } mut suffix := ''
$if !windows {
suffix = ' > /dev/null &'
}
if vweb_logfile != '' {
suffix = ' 2>> $vweb_logfile >> $vweb_logfile &'
}
server_exec_cmd := '$serverexe $sport $exit_after_time $suffix' server_exec_cmd := '$serverexe $sport $exit_after_time $suffix'
$if debug_net_socket_client ? { $if debug_net_socket_client ? {
eprintln('running:\n$server_exec_cmd') eprintln('running:\n$server_exec_cmd')
@ -161,7 +168,7 @@ fn test_http_client_json_post() {
json_for_ouser := json.encode(ouser) json_for_ouser := json.encode(ouser)
mut x := http.post_json('http://127.0.0.1:$sport/json_echo', json_for_ouser) or { panic(err) } mut x := http.post_json('http://127.0.0.1:$sport/json_echo', json_for_ouser) or { panic(err) }
$if debug_net_socket_client ? { $if debug_net_socket_client ? {
eprintln('json response: $x') eprintln('/json_echo endpoint response: $x')
} }
assert x.headers['Content-Type'] == 'application/json' assert x.headers['Content-Type'] == 'application/json'
assert x.text == json_for_ouser assert x.text == json_for_ouser
@ -170,7 +177,7 @@ fn test_http_client_json_post() {
// //
x = http.post_json('http://127.0.0.1:$sport/json', json_for_ouser) or { panic(err) } x = http.post_json('http://127.0.0.1:$sport/json', json_for_ouser) or { panic(err) }
$if debug_net_socket_client ? { $if debug_net_socket_client ? {
eprintln('json response: $x') eprintln('/json endpoint response: $x')
} }
assert x.headers['Content-Type'] == 'application/json' assert x.headers['Content-Type'] == 'application/json'
assert x.text == json_for_ouser assert x.text == json_for_ouser

View File

@ -80,6 +80,7 @@ pub fn (mut app App) user_repo_settings(username string, repository string) vweb
[post] [post]
['/json_echo'] ['/json_echo']
pub fn (mut app App) json_echo() vweb.Result { pub fn (mut app App) json_echo() vweb.Result {
eprintln('>>>>> received http request at /json_echo is: $app.req')
app.set_content_type(app.req.headers['Content-Type']) app.set_content_type(app.req.headers['Content-Type'])
return app.ok(app.req.data) return app.ok(app.req.data)
} }
@ -87,6 +88,7 @@ pub fn (mut app App) json_echo() vweb.Result {
// Make sure [post] works without the path // Make sure [post] works without the path
[post] [post]
pub fn (mut app App) json() vweb.Result { pub fn (mut app App) json() vweb.Result {
eprintln('>>>>> received http request at /json is: $app.req')
app.set_content_type(app.req.headers['Content-Type']) app.set_content_type(app.req.headers['Content-Type'])
return app.ok(app.req.data) return app.ok(app.req.data)
} }

View File

@ -275,10 +275,10 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T) {
mut in_headers := true mut in_headers := true
mut len := 0 mut len := 0
// for line in lines[1..] { // for line in lines[1..] {
for _ in 0 .. 100 { for lindex in 0 .. 100 {
// println(j) // println(j)
line := reader.read_line() or { line := reader.read_line() or {
println('Failed read_line') println('Failed read_line $lindex')
break break
} }
sline := strip(line) sline := strip(line)
@ -419,7 +419,7 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T) {
} else { } else {
route_words_a = attrs.filter(it.to_lower() != 'get').map(it[1..].split('/')) route_words_a = attrs.filter(it.to_lower() != 'get').map(it[1..].split('/'))
} }
if attrs.len == 0 { if attrs.len == 0 || (attrs.len == 1 && attrs[0][0] != `/`) {
// No routing for this method. If it matches, call it and finish matching // No routing for this method. If it matches, call it and finish matching
// since such methods have a priority. // since such methods have a priority.
// For example URL `/register` matches route `/:user`, but `fn register()` // For example URL `/register` matches route `/:user`, but `fn register()`