idbeta commented on a change in pull request #897:
URL: https://github.com/apache/apisix-dashboard/pull/897#discussion_r533952686



##########
File path: api/test/e2e/upstream_test.go
##########
@@ -188,10 +191,198 @@ func TestRoute_Node_Host(t *testing.T) {
        }
 }
 
-//TODO cHash
-//TODO websocket
+func TestUpstream_chash_remote_addr(t *testing.T) {
+       tests := []HttpTestCase{
+               {
+                       caseDesc: "create chash upstream with key 
(remote_addr)",
+                       Object:   ManagerApiExpect(t),
+                       Method:   http.MethodPut,
+                       Path:     "/apisix/admin/upstreams/1",
+                       Body: `{
+                               "nodes": [{
+                                       "host": "172.16.238.20",
+                                       "port": 1980,
+                                       "weight": 1
+                               },
+                               {
+                                       "host": "172.16.238.20",
+                                       "port": 1981,
+                                       "weight": 1
+                               },
+                               {
+                                       "host": "172.16.238.20",
+                                       "port": 1982,
+                                       "weight": 1
+                               }],
+                               "type": "chash",
+                               "hash_on":"header",
+                               "key": "remote_addr"
+                       }`,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+               {
+                       caseDesc: "create route using the upstream just 
created",
+                       Object:   ManagerApiExpect(t),
+                       Method:   http.MethodPut,
+                       Path:     "/apisix/admin/routes/1",
+                       Body: `{
+                               "uri": "/server_port",
+                               "upstream_id": "1"
+                       }`,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+                       Sleep:        sleepTime,
+               },
+       }
+
+       for _, tc := range tests {
+               testCaseCheck(tc)
+       }
+
+       //hit routes
+       basepath := "http://127.0.0.1:9080/";
+       request, err := http.NewRequest("GET", basepath+"/server_port", nil)
+       request.Header.Add("Authorization", token)
+       var resp *http.Response
+       var respBody []byte
+       var count int
+       res := map[string]int{}
+       for i := 0; i <= 17; i++ {
+               resp, err = http.DefaultClient.Do(request)
+               assert.Nil(t, err)
+               respBody, err = ioutil.ReadAll(resp.Body)
+               body := string(respBody)
+               if _, ok := res[body]; !ok {
+                       res[body] = 1
+               } else {
+                       res[body] += 1
+               }
+               resp.Body.Close()
+       }
+       assert.Equal(t, 18, res["1980"]+res["1981"]+res["1982"])

Review comment:
       fixed.




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

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


Reply via email to