{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/pd/pulls/comments/75434692","id":75434692,"diff_hunk":"@@ -0,0 +1,135 @@\n+// Copyright 2016 PingCAP, Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+package api\n+\n+import (\n+\t\"net/http\"\n+\t\"strings\"\n+\t\"time\"\n+\n+\t. \"github.com/pingcap/check\"\n+\t\"github.com/pingcap/pd/server\"\n+)\n+\n+var _ = Suite(&testRedirectorSuite{})\n+\n+type testRedirectorSuite struct {\n+}\n+\n+func (s *testRedirectorSuite) SetUpSuite(c *C) {\n+}\n+\n+func (s *testRedirectorSuite) TearDownSuite(c *C) {\n+}\n+\n+func (s *testRedirectorSuite) TestRedirect(c *C) {\n+\t_, svrs, cleanup := mustNewCluster(c, 3)\n+\tdefer cleanup()\n+\n+\tfor _, svr := range svrs {\n+\t\tmustRequestSuccess(c, svr)\n+\t}\n+}\n+\n+func (s *testRedirectorSuite) TestReconnect(c *C) {\n+\t_, svrs, cleanup := mustNewCluster(c, 3)\n+\tdefer cleanup()\n+\n+\t// Collect two followers.\n+\tvar followers []*server.Server\n+\tleader := mustWaitLeader(c, svrs)\n+\tfor _, svr := range svrs {\n+\t\tif svr != leader {\n+\t\t\tfollowers = append(followers, svr)\n+\t\t}\n+\t}\n+\n+\t// Make connections to followers.\n+\t// Make sure they proxy requests to the leader.\n+\tfor i := 0; i < 2; i++ {\n+\t\tsvr := followers[i]\n+\t\tmustRequestSuccess(c, svr)\n+\t}\n+\n+\t// Close the leader and wait for a new one.\n+\tleader.Close()\n+\tnewLeader := mustWaitLeader(c, followers)\n+\n+\t// Make sure they proxy requests to the new leader.\n+\tfor i := 0; i < 2; i++ {\n+\t\tsvr := followers[i]\n+\t\tmustRequestSuccess(c, svr)\n+\t}\n+\n+\t// Close the new leader and then we have only one node.\n+\tnewLeader.Close()\n+\ttime.Sleep(time.Second)\n+\n+\t// Request will failed with no leader.\n+\tfor i := 0; i < 2; i++ {\n+\t\tsvr := followers[i]\n+\t\tif svr != newLeader {\n+\t\t\tresp := mustRequest(c, svr)\n+\t\t\tc.Assert(resp.StatusCode, Equals, http.StatusInternalServerError)\n+\t\t}\n+\t}\n+}\n+\n+func (s *testRedirectorSuite) TestNotLeader(c *C) {\n+\t_, svrs, cleanup := mustNewCluster(c, 3)\n+\tdefer cleanup()\n+\n+\t// Find a follower.\n+\tvar follower *server.Server\n+\tleader := mustWaitLeader(c, svrs)\n+\tfor _, svr := range svrs {\n+\t\tif svr != leader {\n+\t\t\tfollower = svr\n+\t\t\tbreak\n+\t\t}\n+\t}\n+\n+\tclient := newUnixSocketClient()\n+\n+\tunixAddr := []string{follower.GetAddr(), apiPrefix, \"/api/v1/version\"}\n+\thttpAddr := mustUnixAddrToHTTPAddr(c, strings.Join(unixAddr, \"\"))\n+\n+\t// Request to follower without redirectorHeader is OK.\n+\trequest, err := http.NewRequest(\"GET\", httpAddr, nil)\n+\tc.Assert(err, IsNil)\n+\tresp, err := client.Do(request)\n+\tc.Assert(err, IsNil)\n+\tc.Assert(resp.StatusCode, Equals, http.StatusOK)\n+\n+\t// Request to follower with redirectorHeader will failed.","path":"server/api/redirector_test.go","position":115,"original_position":115,"commit_id":"dbd50d9777f8d9bb71e9deb5aaf4635865001d63","original_commit_id":"02974b5feea651f29235c7268162eb47cd26cd7a","user":{"login":"siddontang","id":1080370,"avatar_url":"https://avatars.githubusercontent.com/u/1080370?v=3","gravatar_id":"","url":"https://api.github.com/users/siddontang","html_url":"https://github.com/siddontang","followers_url":"https://api.github.com/users/siddontang/followers","following_url":"https://api.github.com/users/siddontang/following{/other_user}","gists_url":"https://api.github.com/users/siddontang/gists{/gist_id}","starred_url":"https://api.github.com/users/siddontang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/siddontang/subscriptions","organizations_url":"https://api.github.com/users/siddontang/orgs","repos_url":"https://api.github.com/users/siddontang/repos","events_url":"https://api.github.com/users/siddontang/events{/privacy}","received_events_url":"https://api.github.com/users/siddontang/received_events","type":"User","site_admin":false},"body":"will fail","created_at":"2016-08-19T06:49:03Z","updated_at":"2016-08-19T06:49:03Z","html_url":"https://github.com/pingcap/pd/pull/273#discussion_r75434692","pull_request_url":"https://api.github.com/repos/pingcap/pd/pulls/273","_links":{"self":{"href":"https://api.github.com/repos/pingcap/pd/pulls/comments/75434692"},"html":{"href":"https://github.com/pingcap/pd/pull/273#discussion_r75434692"},"pull_request":{"href":"https://api.github.com/repos/pingcap/pd/pulls/273"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/pd/pulls/273","id":81463964,"html_url":"https://github.com/pingcap/pd/pull/273","diff_url":"https://github.com/pingcap/pd/pull/273.diff","patch_url":"https://github.com/pingcap/pd/pull/273.patch","issue_url":"https://api.github.com/repos/pingcap/pd/issues/273","number":273,"state":"open","locked":false,"title":"redirect request to leader.","user":{"login":"huachaohuang","id":7806468,"avatar_url":"https://avatars.githubusercontent.com/u/7806468?v=3","gravatar_id":"","url":"https://api.github.com/users/huachaohuang","html_url":"https://github.com/huachaohuang","followers_url":"https://api.github.com/users/huachaohuang/followers","following_url":"https://api.github.com/users/huachaohuang/following{/other_user}","gists_url":"https://api.github.com/users/huachaohuang/gists{/gist_id}","starred_url":"https://api.github.com/users/huachaohuang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huachaohuang/subscriptions","organizations_url":"https://api.github.com/users/huachaohuang/orgs","repos_url":"https://api.github.com/users/huachaohuang/repos","events_url":"https://api.github.com/users/huachaohuang/events{/privacy}","received_events_url":"https://api.github.com/users/huachaohuang/received_events","type":"User","site_admin":false},"body":"Redirect API and RPC requests to leader.","created_at":"2016-08-16T12:37:59Z","updated_at":"2016-08-19T06:49:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3defe6a79914afb88a0c830735fda5ffeec9c841","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/pd/pulls/273/commits","review_comments_url":"https://api.github.com/repos/pingcap/pd/pulls/273/comments","review_comment_url":"https://api.github.com/repos/pingcap/pd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/pd/issues/273/comments","statuses_url":"https://api.github.com/repos/pingcap/pd/statuses/dbd50d9777f8d9bb71e9deb5aaf4635865001d63","head":{"label":"pingcap:huachaohuang/redirect-request-to-leader","ref":"huachaohuang/redirect-request-to-leader","sha":"dbd50d9777f8d9bb71e9deb5aaf4635865001d63","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":53311716,"name":"pd","full_name":"pingcap/pd","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/pd","description":"Placement driver for TiKV","fork":false,"url":"https://api.github.com/repos/pingcap/pd","forks_url":"https://api.github.com/repos/pingcap/pd/forks","keys_url":"https://api.github.com/repos/pingcap/pd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/pd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/pd/teams","hooks_url":"https://api.github.com/repos/pingcap/pd/hooks","issue_events_url":"https://api.github.com/repos/pingcap/pd/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/pd/events","assignees_url":"https://api.github.com/repos/pingcap/pd/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/pd/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/pd/tags","blobs_url":"https://api.github.com/repos/pingcap/pd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/pd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/pd/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/pd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/pd/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/pd/languages","stargazers_url":"https://api.github.com/repos/pingcap/pd/stargazers","contributors_url":"https://api.github.com/repos/pingcap/pd/contributors","subscribers_url":"https://api.github.com/repos/pingcap/pd/subscribers","subscription_url":"https://api.github.com/repos/pingcap/pd/subscription","commits_url":"https://api.github.com/repos/pingcap/pd/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/pd/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/pd/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/pd/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/pd/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/pd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/pd/merges","archive_url":"https://api.github.com/repos/pingcap/pd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/pd/downloads","issues_url":"https://api.github.com/repos/pingcap/pd/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/pd/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/pd/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/pd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/pd/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/pd/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/pd/deployments","created_at":"2016-03-07T09:13:06Z","updated_at":"2016-08-03T16:23:03Z","pushed_at":"2016-08-19T06:45:39Z","git_url":"git://github.com/pingcap/pd.git","ssh_url":"git@github.com:pingcap/pd.git","clone_url":"https://github.com/pingcap/pd.git","svn_url":"https://github.com/pingcap/pd","homepage":"","size":3452,"stargazers_count":17,"watchers_count":17,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":15,"forks":4,"open_issues":15,"watchers":17,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"63d02a6d070a64ce5719f2d144121278efafbd6b","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":53311716,"name":"pd","full_name":"pingcap/pd","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/pd","description":"Placement driver for TiKV","fork":false,"url":"https://api.github.com/repos/pingcap/pd","forks_url":"https://api.github.com/repos/pingcap/pd/forks","keys_url":"https://api.github.com/repos/pingcap/pd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/pd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/pd/teams","hooks_url":"https://api.github.com/repos/pingcap/pd/hooks","issue_events_url":"https://api.github.com/repos/pingcap/pd/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/pd/events","assignees_url":"https://api.github.com/repos/pingcap/pd/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/pd/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/pd/tags","blobs_url":"https://api.github.com/repos/pingcap/pd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/pd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/pd/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/pd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/pd/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/pd/languages","stargazers_url":"https://api.github.com/repos/pingcap/pd/stargazers","contributors_url":"https://api.github.com/repos/pingcap/pd/contributors","subscribers_url":"https://api.github.com/repos/pingcap/pd/subscribers","subscription_url":"https://api.github.com/repos/pingcap/pd/subscription","commits_url":"https://api.github.com/repos/pingcap/pd/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/pd/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/pd/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/pd/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/pd/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/pd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/pd/merges","archive_url":"https://api.github.com/repos/pingcap/pd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/pd/downloads","issues_url":"https://api.github.com/repos/pingcap/pd/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/pd/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/pd/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/pd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/pd/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/pd/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/pd/deployments","created_at":"2016-03-07T09:13:06Z","updated_at":"2016-08-03T16:23:03Z","pushed_at":"2016-08-19T06:45:39Z","git_url":"git://github.com/pingcap/pd.git","ssh_url":"git@github.com:pingcap/pd.git","clone_url":"https://github.com/pingcap/pd.git","svn_url":"https://github.com/pingcap/pd","homepage":"","size":3452,"stargazers_count":17,"watchers_count":17,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":15,"forks":4,"open_issues":15,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/pd/pulls/273"},"html":{"href":"https://github.com/pingcap/pd/pull/273"},"issue":{"href":"https://api.github.com/repos/pingcap/pd/issues/273"},"comments":{"href":"https://api.github.com/repos/pingcap/pd/issues/273/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/pd/pulls/273/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/pd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/pd/pulls/273/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/pd/statuses/dbd50d9777f8d9bb71e9deb5aaf4635865001d63"}}}}
{"actor":{"display_login":"siddontang"}}