okaybase commented on a change in pull request #4965:
URL: https://github.com/apache/apisix/pull/4965#discussion_r705127530



##########
File path: t/plugin/proxy-mirror.t
##########
@@ -445,3 +455,163 @@ GET /t
 passed
 --- no_error_log
 [error]
+
+
+
+=== TEST 13: sanity check (invalid sample_ratio)
+--- config
+       location /t {
+           content_by_lua_block {
+               local t = require("lib.test_admin").test
+               local code, body = t('/apisix/admin/routes/1',
+                    ngx.HTTP_PUT,
+                    [[{
+                        "plugins": {
+                            "proxy-mirror": {
+                               "host": "http://127.0.0.1:1986";,
+                               "sample_ratio": 10
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/hello"
+                   }]]
+                   )
+
+               if code >= 300 then
+                   ngx.status = code
+               end
+               ngx.print(body)
+           }
+       }
+--- request
+GET /t
+--- error_code: 400
+--- response_body
+{"error_msg":"failed to check the configuration of plugin proxy-mirror err: 
property \"sample_ratio\" validation failed: expected 10 to be smaller than 1"}
+--- no_error_log
+[error]
+
+
+
+=== TEST 14: set mirror requests sample_ratio to 1
+--- config
+       location /t {
+           content_by_lua_block {
+               local t = require("lib.test_admin").test
+               local code, body = t('/apisix/admin/routes/1',
+                    ngx.HTTP_PUT,
+                    [[{
+                        "plugins": {
+                            "proxy-mirror": {
+                               "host": "http://127.0.0.1:1986";,
+                               "sample_ratio": 1
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/hello"
+                   }]]
+                   )
+
+               if code >= 300 then
+                   ngx.status = code
+               end
+               ngx.say(body)
+           }
+       }
+--- request
+GET /t
+--- error_code: 200
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: hit route with sample_ratio 1
+--- request
+GET /hello?sample_ratio=1
+--- error_code: 200
+--- response_body
+hello world
+--- error_log_like eval
+qr/uri: \/hello\?sample_ratio=1/
+
+
+
+=== TEST 16: set mirror requests sample_ratio to 0.5
+--- config
+       location /t {
+           content_by_lua_block {
+                local http = require("resty.http")
+               local core = require("apisix.core")
+               local t = require("lib.test_admin").test
+               local code, body = t('/apisix/admin/routes/1',
+                    ngx.HTTP_PUT,
+                    [[{
+                        "plugins": {
+                            "proxy-mirror": {
+                               "host": "http://127.0.0.1:1986";,
+                               "sample_ratio": 0.5
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/hello"
+                   }]]
+                   )
+
+               if code == 200 then
+                    -- reset count
+                    local count = 0
+                    local httpc = http.new()
+                    local url = "http://127.0.0.1:1980/stat_count?action=reset";
+                    local res, err = httpc:request_uri(url, {method = "GET"})
+                    if not res then
+                        core.log.error(err)
+                    else
+                        core.log.info("reset the mirror request stat count to 
" .. res.body)
+                        count = res.body
+                    end
+
+                   for i = 1, 200 do
+                       t('/hello?sample_ratio=0.5', ngx.HTTP_GET)
+                   end
+
+                    url = "http://127.0.0.1:1980/stat_count";
+                    res, err = httpc:request_uri(url, {method = "GET"})
+                    if not res then
+                        core.log.error(err)
+                    else
+                        core.log.info("the mirror request stat count is " .. 
res.body)
+                        count = res.body
+                    end
+                   assert(count >= 75 and count <= 125)
+               elseif code >= 300 then
+                   ngx.status = code
+               end
+               ngx.say(body)
+           }
+       }
+--- request
+GET /t
+--- error_code: 200
+--- response_body
+passed
+--- error_log_like eval
+qr/(uri: \/hello\?sample_ratio=0\.5){75,125}/
+--- timeout: 60

Review comment:
       okay, the test case has changed to send requests parallelly, but the ci 
log don't show more info about the test status 500, could you have a look at 
it~ @spacewander 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to