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



##########
File path: t/plugin/proxy-mirror.t
##########
@@ -445,3 +445,139 @@ 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 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
+                   for i = 1, 200 do
+                       t('/hello?sample_ratio=0.5', ngx.HTTP_GET)

Review comment:
       okay~ will write a new backend API~




-- 
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