Skip to content

Commit 92c29e7

Browse files
tests: added three cases for upstream keepalive. (#51)
test 1/2: upstream send extra data. test 3: upstream close the connection.
1 parent 77d1c39 commit 92c29e7

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
sudo: required
22
dist: trusty
33

4+
branches:
5+
only:
6+
- "plus"
7+
48
os: linux
59

610
language: c

t/balancer-keepalive.t

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,3 +1258,169 @@ SNI=one
12581258
qr/^lua balancer: keepalive no free connection, host: 127.0.0.1:23456, name: host1
12591259
lua balancer: keepalive saving connection \S+, host: 127.0.0.1:23456, name: host1
12601260
$/
1261+
1262+
1263+
1264+
=== TEST 29: keepalive idle connection recv data
1265+
--- main_config
1266+
stream {
1267+
server {
1268+
listen 60123 ssl;
1269+
ssl_certificate ../../cert/test.crt;
1270+
ssl_certificate_key ../../cert/test.key;
1271+
content_by_lua_block {
1272+
ngx.say("HTTP/1.1 200 OK")
1273+
ngx.say("Content-Length: 10")
1274+
ngx.say("Connection: keep-alive\n")
1275+
ngx.print("0123456789")
1276+
ngx.sleep(0.01)
1277+
ngx.print("trigger")
1278+
}
1279+
}
1280+
}
1281+
1282+
--- http_upstream
1283+
upstream test_upstream {
1284+
server 0.0.0.1;
1285+
1286+
balancer_by_lua_block {
1287+
local b = require "ngx.balancer"
1288+
1289+
local ok, err = b.set_current_peer("127.0.0.1",
1290+
60123,
1291+
nil,
1292+
ngx.var.arg_host)
1293+
if not ok then
1294+
ngx.log(ngx.ERR, "failed to set current peer: ", err)
1295+
return
1296+
end
1297+
1298+
local ok, err = b.enable_keepalive()
1299+
if not ok then
1300+
ngx.log(ngx.ERR, "failed to set keepalive: ", err)
1301+
return
1302+
end
1303+
}
1304+
}
1305+
--- config
1306+
location = /t {
1307+
echo_subrequest GET '/proxy/echo_sni' -q 'sni=one&host=host1';
1308+
}
1309+
--- wait: 0.2
1310+
--- response_body chomp
1311+
0123456789
1312+
--- grep_error_log_out eval
1313+
qr/^lua balancer: keepalive no free connection, host: 127.0.0.1:60123, name: host1
1314+
lua balancer: keepalive saving connection (\S+?), host: 127.0.0.1:60123, name: host1
1315+
lua balancer: keepalive closing connection \1
1316+
$/
1317+
1318+
1319+
1320+
=== TEST 30: keepalive idle connection recv data
1321+
--- main_config
1322+
stream {
1323+
server {
1324+
listen 60123 ssl;
1325+
ssl_certificate ../../cert/test.crt;
1326+
ssl_certificate_key ../../cert/test.key;
1327+
content_by_lua_block {
1328+
ngx.say("HTTP/1.1 200 OK")
1329+
ngx.say("Content-Length: 10")
1330+
ngx.say("Connection: keep-alive\n")
1331+
ngx.print("012345678912345")
1332+
ngx.sleep(0.01)
1333+
}
1334+
}
1335+
}
1336+
1337+
--- http_upstream
1338+
upstream test_upstream {
1339+
server 0.0.0.1;
1340+
1341+
balancer_by_lua_block {
1342+
local b = require "ngx.balancer"
1343+
1344+
local ok, err = b.set_current_peer("127.0.0.1",
1345+
60123,
1346+
nil,
1347+
ngx.var.arg_host)
1348+
if not ok then
1349+
ngx.log(ngx.ERR, "failed to set current peer: ", err)
1350+
return
1351+
end
1352+
1353+
local ok, err = b.enable_keepalive()
1354+
if not ok then
1355+
ngx.log(ngx.ERR, "failed to set keepalive: ", err)
1356+
return
1357+
end
1358+
}
1359+
}
1360+
--- config
1361+
location = /t {
1362+
echo_subrequest GET '/proxy/echo_sni' -q 'sni=one&host=host1';
1363+
}
1364+
--- wait: 0.2
1365+
--- response_body chomp
1366+
0123456789
1367+
--- grep_error_log_out eval
1368+
qr/^lua balancer: keepalive no free connection, host: 127.0.0.1:60123, name: host1
1369+
lua balancer: keepalive not saving connection \S+
1370+
$/
1371+
1372+
1373+
1374+
=== TEST 31: keepalive idle connection recv data
1375+
--- main_config
1376+
stream {
1377+
server {
1378+
listen 60123 ssl;
1379+
ssl_certificate ../../cert/test.crt;
1380+
ssl_certificate_key ../../cert/test.key;
1381+
content_by_lua_block {
1382+
ngx.say("HTTP/1.1 200 OK")
1383+
ngx.say("Content-Length: 10")
1384+
ngx.say("Connection: keep-alive\n")
1385+
ngx.print("0123456789")
1386+
ngx.flush()
1387+
ngx.sleep(0.01)
1388+
}
1389+
}
1390+
}
1391+
1392+
--- http_upstream
1393+
upstream test_upstream {
1394+
server 0.0.0.1;
1395+
1396+
balancer_by_lua_block {
1397+
local b = require "ngx.balancer"
1398+
1399+
local ok, err = b.set_current_peer("127.0.0.1",
1400+
60123,
1401+
nil,
1402+
ngx.var.arg_host)
1403+
if not ok then
1404+
ngx.log(ngx.ERR, "failed to set current peer: ", err)
1405+
return
1406+
end
1407+
1408+
local ok, err = b.enable_keepalive()
1409+
if not ok then
1410+
ngx.log(ngx.ERR, "failed to set keepalive: ", err)
1411+
return
1412+
end
1413+
}
1414+
}
1415+
--- config
1416+
location = /t {
1417+
echo_subrequest GET '/proxy/echo_sni' -q 'sni=one&host=host1';
1418+
}
1419+
--- wait: 0.2
1420+
--- response_body chomp
1421+
0123456789
1422+
--- grep_error_log_out eval
1423+
qr/^lua balancer: keepalive no free connection, host: 127.0.0.1:60123, name: host1
1424+
lua balancer: keepalive saving connection (\S+?), host: 127.0.0.1:60123, name: host1
1425+
lua balancer: keepalive closing connection \1
1426+
$/

0 commit comments

Comments
 (0)