GitHub PullRequestReviewCommentEvent at 2014-03-20 01:58:14
Repository: go-discoverd
Actor: titanous
Payload: {"comment":{"url":"https://api.github.com/repos/flynn/go-discoverd/pulls/comments/10780371","id":10780371,"diff_hunk":"@@ -0,0 +1,89 @@\n+package balancer\n+\n+import (\n+\t\"github.com/flynn/discoverd/agent\"\n+\t\"github.com/flynn/go-discoverd\"\n+\t\"math/rand\"\n+\t\"testing\"\n+)\n+\n+// implements discoverd.ServiceSet\n+type TestSet struct {\n+\tservices []*discoverd.Service\n+}\n+\n+func (test *TestSet) SelfAddr() string { return \"127.0.0.1\" }\n+\n+func (test *TestSet) Leader() *discoverd.Service { return test.services[0] }\n+\n+func (test *TestSet) Leaders() chan *discoverd.Service { return nil }\n+\n+func (test *TestSet) Services() []*discoverd.Service { return test.services }\n+\n+func (test *TestSet) Addrs() []string { return []string{} }\n+\n+func (test *TestSet) Select(attrs map[string]string) []*discoverd.Service { return test.services }\n+\n+func (test *TestSet) Filter(attrs map[string]string) {}\n+\n+func (test *TestSet) Watch(bringCurrent bool, fireOnce bool) chan *agent.ServiceUpdate { return nil }\n+\n+func (test *TestSet) Unwatch(chan *agent.ServiceUpdate) {}\n+\n+func (test *TestSet) Close() error { return nil }\n+\n+func NewTestSet() discoverd.ServiceSet {\n+\treturn &TestSet{\n+\t\t[]*discoverd.Service{\n+\t\t\t&discoverd.Service{Host: \"flying-manta-10.flynn.io\"},\n+\t\t\t&discoverd.Service{Host: \"singing-shark-82.flynn.io\"},\n+\t\t\t&discoverd.Service{Host: \"passionate-sheep-19.flynn.io\"},\n+\t\t},\n+\t}\n+}\n+\n+func assertHost(balancer LoadBalancer, expected string, t *testing.T) {\n+\tservice, err := balancer.Next()\n+\tif err != nil {\n+\t\tt.Fatal(\"Did not expect balancer to yield an error: \", err.Error())\n+\t}\n+\tif service.Host != expected {\n+\t\tt.Fatalf(\"Expected %s, got %s\", expected, service.Host)\n+\t}\n+}\n+\n+func TestRandom(t *testing.T) {\n+\tset := NewTestSet()\n+\tbalancer := Random(set, rand.NewSource(100))\n+\n+\tassertHost(balancer, \"singing-shark-82.flynn.io\", t)\n+\tassertHost(balancer, \"passionate-sheep-19.flynn.io\", t)\n+\tassertHost(balancer, \"singing-shark-82.flynn.io\", t)\n+\tassertHost(balancer, \"flying-manta-10.flynn.io\", t)\n+}\n+\n+func TestRoundRobin(t *testing.T) {\n+\tset := NewTestSet()\n+\tbalancer := RoundRobin(set)","path":"balancer/balancer_test.go","position":67,"original_position":67,"commit_id":"56018f6f30d9e3d641c7a532a8e9a5aa2903ee1f","original_commit_id":"56018f6f30d9e3d641c7a532a8e9a5aa2903ee1f","user":{"login":"titanous","id":13026,"avatar_url":"https://avatars.githubusercontent.com/u/13026?","gravatar_id":"02319fb5cbcf9309a4bd0ea7c791e5d6","url":"https://api.github.com/users/titanous","html_url":"https://github.com/titanous","followers_url":"https://api.github.com/users/titanous/followers","following_url":"https://api.github.com/users/titanous/following{/other_user}","gists_url":"https://api.github.com/users/titanous/gists{/gist_id}","starred_url":"https://api.github.com/users/titanous/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/titanous/subscriptions","organizations_url":"https://api.github.com/users/titanous/orgs","repos_url":"https://api.github.com/users/titanous/repos","events_url":"https://api.github.com/users/titanous/events{/privacy}","received_events_url":"https://api.github.com/users/titanous/received_events","type":"User","site_admin":false},"body":"```go\r\nbalancer := RoundRobin(NewTestSet())\r\n```","created_at":"2014-03-20T01:58:14Z","updated_at":"2014-03-20T01:58:14Z","html_url":"https://github.com/flynn/go-discoverd/pull/24#discussion_r10780371","pull_request_url":"https://api.github.com/repos/flynn/go-discoverd/pulls/24","_links":{"self":{"href":"https://api.github.com/repos/flynn/go-discoverd/pulls/comments/10780371"},"html":{"href":"https://github.com/flynn/go-discoverd/pull/24#discussion_r10780371"},"pull_request":{"href":"https://api.github.com/repos/flynn/go-discoverd/pulls/24"}}}}