From b29aa0f4b112f8bee67da1736830a0884a283b5d Mon Sep 17 00:00:00 2001 From: spacewander Date: Thu, 11 Jan 2018 14:53:47 +0800 Subject: [PATCH] tests: corrected the handshake flag position. We should set the handshake done flag when the handshake is totally finished, not just before the first handshake. The incorrect handshake flag caused some random test failures seen in travis build and developers' machine. --- t/ssl-session-fetch.t | 17 ++++++++++------- t/ssl.t | 11 +++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/t/ssl-session-fetch.t b/t/ssl-session-fetch.t index af9646737..71f6bcd0a 100644 --- a/t/ssl-session-fetch.t +++ b/t/ssl-session-fetch.t @@ -414,8 +414,6 @@ $/s, local sid = ssl.get_session_id() print("session id: ", sid) - - ngx.shared.done:set("handshake", true) } ssl_session_fetch_by_lua_block { @@ -430,8 +428,6 @@ $/s, if not ok or err then print("failed to resume session: ", err) end - - -- ngx.shared.done:set("handshake", true) } server { @@ -440,6 +436,12 @@ $/s, ssl_session_tickets off; ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt; ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key; + + location / { + content_by_lua_block { + ngx.shared.done:set("handshake", true) + } + } } --- config lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt; @@ -451,12 +453,13 @@ $/s, ngx.shared.done:delete("handshake") local addr = ngx.var.addr; local sess = ngx.var.sess_file + local req = "'GET / HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n'" local f, err if not package.loaded.session then - f, err = io.popen("echo 'Q' | timeout 3s openssl s_client -connect " .. addr .. " -sess_out " .. sess) + f, err = io.popen("echo -n " .. req .. " | timeout 3s openssl s_client -connect " .. addr .. " -sess_out " .. sess) package.loaded.session = true else - f, err = io.popen("echo 'Q' | timeout 3s openssl s_client -connect " .. addr .. " -sess_in " .. sess) + f, err = io.popen("echo -n " .. req .. " | timeout 3s openssl s_client -connect " .. addr .. " -sess_in " .. sess) end if not f then @@ -465,7 +468,7 @@ $/s, end local step = 0.001 - while step < 1 do + while step < 2 do ngx.sleep(step) step = step * 2 diff --git a/t/ssl.t b/t/ssl.t index 6538c4f1f..cc8a9b53a 100644 --- a/t/ssl.t +++ b/t/ssl.t @@ -2211,13 +2211,11 @@ client ip: 127.0.0.1 ngx.log(ngx.ERR, "failed to set DER cert: ", err) return end - - ngx.shared.done:set("handshake", true) } - location /foo { + location / { content_by_lua_block { - ngx.exit(201) + ngx.shared.done:set("handshake", true) } } } @@ -2228,14 +2226,15 @@ client ip: 127.0.0.1 content_by_lua_block { ngx.shared.done:delete("handshake") local addr = ngx.var.addr; - local f, err = io.popen("echo 'Q' | timeout 3s openssl s_client -connect 127.0.0.1:$TEST_NGINX_SERVER_SSL_PORT") + local req = "'GET / HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n'" + local f, err = io.popen("echo -n " .. req .. " | timeout 3s openssl s_client -connect 127.0.0.1:$TEST_NGINX_SERVER_SSL_PORT") if not f then ngx.say(err) return end local step = 0.001 - while step < 1 do + while step < 2 do ngx.sleep(step) step = step * 2