Skip to content

Commit

Permalink
test: old test case is unstable, running fail sometimes. (#1925)
Browse files Browse the repository at this point in the history
  • Loading branch information
membphis committed Jul 31, 2020
1 parent 8fc2af5 commit 3d8150b
Showing 1 changed file with 38 additions and 22 deletions.
60 changes: 38 additions & 22 deletions t/node/invalid-upstream.t
Expand Up @@ -65,38 +65,58 @@ qr{invalid item data of \[/apisix/upstreams/1\], val: mexxxxxxxxxxxxxxx, it shou
=== TEST 3: set vinalid upstream(wrong type)
=== TEST 3: delete invalid upstream(id: 1)
--- config
location /t {
content_by_lua_block {
local core = require("apisix.core")
local res, err = core.etcd.set("/upstreams/1", core.json.decode([[{
local res, err = core.etcd.delete("/upstreams/1")
if res.status >= 300 then
res.status = code
end
ngx.say("passed")
ngx.sleep(1)
}
}
--- request
GET /t
--- response_body
passed
=== TEST 4: invalid upstream(wrong type)
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/upstreams/1',
ngx.HTTP_PUT,
[[{
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin_invalid"
}]]))
}]]
)
if res.status >= 300 then
res.status = code
if code >= 300 then
ngx.status = code
end
ngx.print(core.json.encode(res.body))
ngx.sleep(0.5)
ngx.print(body)
}
}
--- request
GET /t
--- response_body_like eval
qr/"nodes":\{"127.0.0.1:1980":1\}/
--- grep_error_log eval
qr/\[error\].*/
--- grep_error_log_out eval
qr{invalid item data of \[/apisix/upstreams/1\], val: mexxxxxxxxxxxxxxx, it shoud be a object}
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"type\" validation failed: matches non of the enum values"}
=== TEST 4: set valid upstream(id: 1)
=== TEST 5: set valid upstream(id: 1)
--- config
location /t {
content_by_lua_block {
Expand All @@ -107,11 +127,9 @@ qr{invalid item data of \[/apisix/upstreams/1\], val: mexxxxxxxxxxxxxxx, it shou
},
"type": "roundrobin"
}]]))
if res.status >= 300 then
res.status = code
end
ngx.print(core.json.encode(res.body))
ngx.sleep(1)
}
Expand All @@ -120,14 +138,12 @@ qr{invalid item data of \[/apisix/upstreams/1\], val: mexxxxxxxxxxxxxxx, it shou
GET /t
--- response_body_like eval
qr/"nodes":\{"127.0.0.1:1980":1\}/
--- grep_error_log eval
qr/\[error\].*/
--- grep_error_log_out eval
qr{failed to check item data of \[/apisix/upstreams\] err:property "type" validation failed}
--- no_error_log
[error]
=== TEST 5: no error log
=== TEST 6: no error log
--- config
location /t {
content_by_lua_block {
Expand Down

0 comments on commit 3d8150b

Please sign in to comment.