{"action":"created","comment":{"url":"https://api.github.com/repos/go-kit/kit/pulls/comments/53377077","id":53377077,"diff_hunk":"@@ -174,38 +176,74 @@ func (c *fakeClient) GetEntries(path string) ([]string, <-chan zk.Event, error)\n }\n \n func (c *fakeClient) AddService(node, data string) {\n+\tc.mtx.Lock()\n+\tdefer c.mtx.Unlock()\n \tc.responses[node] = data\n-\tc.triggerWatch()\n+\tc.ch <- zk.Event{}\n }\n \n func (c *fakeClient) RemoveService(node string) {\n+\tc.mtx.Lock()\n+\tdefer c.mtx.Unlock()\n \tdelete(c.responses, node)\n-\tc.triggerWatch()\n+\tc.ch <- zk.Event{}\n }\n \n func (c *fakeClient) SendErrorOnWatch() {\n+\tc.mtx.Lock()\n+\tdefer c.mtx.Unlock()\n \tc.result = false\n-\tc.triggerWatch()\n+\tc.ch <- zk.Event{}\n+}\n+\n+func (c *fakeClient) ErrorIsConsumed(t time.Duration) error {\n+\ttimeout := time.After(t)\n+\tfor {\n+\t\tselect {\n+\t\tcase <-timeout:\n+\t\t\terrMsg := fmt.Sprintf(\"expected error not consumed after timeout %s\", t.String())\n+\t\t\treturn errors.New(errMsg)\n+\t\tdefault:\n+\t\t\tc.mtx.Lock()\n+\t\t\tif c.result == false {\n+\t\t\t\tc.mtx.Unlock()\n+\t\t\t\treturn nil\n+\t\t\t}\n+\t\t\tc.mtx.Unlock()\n+\t\t}\n+\t}\n }\n \n func (c *fakeClient) Stop() {}\n \n func newFactory(fakeError string) loadbalancer.Factory {\n-\treturn func(string) (endpoint.Endpoint, io.Closer, error) {\n-\t\tif fakeError == \"\" {\n-\t\t\treturn e, nil, nil\n+\treturn func(instance string) (endpoint.Endpoint, io.Closer, error) {\n+\t\tif fakeError == instance {\n+\t\t\treturn nil, nil, errors.New(fakeError)\n \t\t}\n-\t\treturn nil, nil, errors.New(fakeError)\n+\t\treturn e, nil, nil\n \t}\n }\n \n-func (c *fakeClient) triggerWatch() {\n-\tc.ch <- zk.Event{}\n-\t// watches on ZooKeeper Nodes trigger once, most ZooKeeper libraries also\n-\t// implement \"fire once\" channels for these watches\n-\tclose(c.ch)\n-\tc.ch = make(chan zk.Event, 1)\n-\n-\t// make sure we allow the Publisher to handle this update\n-\ttime.Sleep(1 * time.Millisecond)\n+func asyncTest(timeout time.Duration, want int, p *Publisher) (err error) {\n+\tvar endpoints []endpoint.Endpoint\n+\t// want can never be -1\n+\thave := -1\n+\tt := time.After(timeout)\n+\tfor {\n+\t\tselect {\n+\t\tcase <-t:\n+\t\t\terrMsg := fmt.Sprintf(\"want %d, have %d after timeout %s\", want, have, timeout.String())\n+\t\t\terr = errors.New(errMsg)","path":"loadbalancer/zk/publisher_test.go","position":228,"original_position":228,"commit_id":"1f495fdef67e1edc2d423c41686b1f858d8d8c25","original_commit_id":"1f495fdef67e1edc2d423c41686b1f858d8d8c25","user":{"login":"peterbourgon","id":114509,"avatar_url":"https://avatars.githubusercontent.com/u/114509?v=3","gravatar_id":"","url":"https://api.github.com/users/peterbourgon","html_url":"https://github.com/peterbourgon","followers_url":"https://api.github.com/users/peterbourgon/followers","following_url":"https://api.github.com/users/peterbourgon/following{/other_user}","gists_url":"https://api.github.com/users/peterbourgon/gists{/gist_id}","starred_url":"https://api.github.com/users/peterbourgon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterbourgon/subscriptions","organizations_url":"https://api.github.com/users/peterbourgon/orgs","repos_url":"https://api.github.com/users/peterbourgon/repos","events_url":"https://api.github.com/users/peterbourgon/events{/privacy}","received_events_url":"https://api.github.com/users/peterbourgon/received_events","type":"User","site_admin":false},"body":"fmt.Errorf?","created_at":"2016-02-18T20:26:01Z","updated_at":"2016-02-18T20:26:01Z","html_url":"https://github.com/go-kit/kit/pull/195#discussion_r53377077","pull_request_url":"https://api.github.com/repos/go-kit/kit/pulls/195","_links":{"self":{"href":"https://api.github.com/repos/go-kit/kit/pulls/comments/53377077"},"html":{"href":"https://github.com/go-kit/kit/pull/195#discussion_r53377077"},"pull_request":{"href":"https://api.github.com/repos/go-kit/kit/pulls/195"}}},"pull_request":{"url":"https://api.github.com/repos/go-kit/kit/pulls/195","id":59342718,"html_url":"https://github.com/go-kit/kit/pull/195","diff_url":"https://github.com/go-kit/kit/pull/195.diff","patch_url":"https://github.com/go-kit/kit/pull/195.patch","issue_url":"https://api.github.com/repos/go-kit/kit/issues/195","number":195,"state":"open","locked":false,"title":"Fixes for ZooKeeper Publisher Tests (race conditions and close panic)","user":{"login":"basvanbeek","id":7205296,"avatar_url":"https://avatars.githubusercontent.com/u/7205296?v=3","gravatar_id":"","url":"https://api.github.com/users/basvanbeek","html_url":"https://github.com/basvanbeek","followers_url":"https://api.github.com/users/basvanbeek/followers","following_url":"https://api.github.com/users/basvanbeek/following{/other_user}","gists_url":"https://api.github.com/users/basvanbeek/gists{/gist_id}","starred_url":"https://api.github.com/users/basvanbeek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basvanbeek/subscriptions","organizations_url":"https://api.github.com/users/basvanbeek/orgs","repos_url":"https://api.github.com/users/basvanbeek/repos","events_url":"https://api.github.com/users/basvanbeek/events{/privacy}","received_events_url":"https://api.github.com/users/basvanbeek/received_events","type":"User","site_admin":false},"body":"This should take care of the close panic and race conditions in the mocked Client.","created_at":"2016-02-15T10:07:43Z","updated_at":"2016-02-18T20:26:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"57d4f0abd76298812be98cfe7b9cf4bf7b35f0ec","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/go-kit/kit/pulls/195/commits","review_comments_url":"https://api.github.com/repos/go-kit/kit/pulls/195/comments","review_comment_url":"https://api.github.com/repos/go-kit/kit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/go-kit/kit/issues/195/comments","statuses_url":"https://api.github.com/repos/go-kit/kit/statuses/1f495fdef67e1edc2d423c41686b1f858d8d8c25","head":{"label":"basvanbeek:zktest","ref":"zktest","sha":"1f495fdef67e1edc2d423c41686b1f858d8d8c25","user":{"login":"basvanbeek","id":7205296,"avatar_url":"https://avatars.githubusercontent.com/u/7205296?v=3","gravatar_id":"","url":"https://api.github.com/users/basvanbeek","html_url":"https://github.com/basvanbeek","followers_url":"https://api.github.com/users/basvanbeek/followers","following_url":"https://api.github.com/users/basvanbeek/following{/other_user}","gists_url":"https://api.github.com/users/basvanbeek/gists{/gist_id}","starred_url":"https://api.github.com/users/basvanbeek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basvanbeek/subscriptions","organizations_url":"https://api.github.com/users/basvanbeek/orgs","repos_url":"https://api.github.com/users/basvanbeek/repos","events_url":"https://api.github.com/users/basvanbeek/events{/privacy}","received_events_url":"https://api.github.com/users/basvanbeek/received_events","type":"User","site_admin":false},"repo":{"id":38117114,"name":"kit","full_name":"basvanbeek/kit","owner":{"login":"basvanbeek","id":7205296,"avatar_url":"https://avatars.githubusercontent.com/u/7205296?v=3","gravatar_id":"","url":"https://api.github.com/users/basvanbeek","html_url":"https://github.com/basvanbeek","followers_url":"https://api.github.com/users/basvanbeek/followers","following_url":"https://api.github.com/users/basvanbeek/following{/other_user}","gists_url":"https://api.github.com/users/basvanbeek/gists{/gist_id}","starred_url":"https://api.github.com/users/basvanbeek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basvanbeek/subscriptions","organizations_url":"https://api.github.com/users/basvanbeek/orgs","repos_url":"https://api.github.com/users/basvanbeek/repos","events_url":"https://api.github.com/users/basvanbeek/events{/privacy}","received_events_url":"https://api.github.com/users/basvanbeek/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/basvanbeek/kit","description":"A Go toolkit for microservices.","fork":true,"url":"https://api.github.com/repos/basvanbeek/kit","forks_url":"https://api.github.com/repos/basvanbeek/kit/forks","keys_url":"https://api.github.com/repos/basvanbeek/kit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/basvanbeek/kit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/basvanbeek/kit/teams","hooks_url":"https://api.github.com/repos/basvanbeek/kit/hooks","issue_events_url":"https://api.github.com/repos/basvanbeek/kit/issues/events{/number}","events_url":"https://api.github.com/repos/basvanbeek/kit/events","assignees_url":"https://api.github.com/repos/basvanbeek/kit/assignees{/user}","branches_url":"https://api.github.com/repos/basvanbeek/kit/branches{/branch}","tags_url":"https://api.github.com/repos/basvanbeek/kit/tags","blobs_url":"https://api.github.com/repos/basvanbeek/kit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/basvanbeek/kit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/basvanbeek/kit/git/refs{/sha}","trees_url":"https://api.github.com/repos/basvanbeek/kit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/basvanbeek/kit/statuses/{sha}","languages_url":"https://api.github.com/repos/basvanbeek/kit/languages","stargazers_url":"https://api.github.com/repos/basvanbeek/kit/stargazers","contributors_url":"https://api.github.com/repos/basvanbeek/kit/contributors","subscribers_url":"https://api.github.com/repos/basvanbeek/kit/subscribers","subscription_url":"https://api.github.com/repos/basvanbeek/kit/subscription","commits_url":"https://api.github.com/repos/basvanbeek/kit/commits{/sha}","git_commits_url":"https://api.github.com/repos/basvanbeek/kit/git/commits{/sha}","comments_url":"https://api.github.com/repos/basvanbeek/kit/comments{/number}","issue_comment_url":"https://api.github.com/repos/basvanbeek/kit/issues/comments{/number}","contents_url":"https://api.github.com/repos/basvanbeek/kit/contents/{+path}","compare_url":"https://api.github.com/repos/basvanbeek/kit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/basvanbeek/kit/merges","archive_url":"https://api.github.com/repos/basvanbeek/kit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/basvanbeek/kit/downloads","issues_url":"https://api.github.com/repos/basvanbeek/kit/issues{/number}","pulls_url":"https://api.github.com/repos/basvanbeek/kit/pulls{/number}","milestones_url":"https://api.github.com/repos/basvanbeek/kit/milestones{/number}","notifications_url":"https://api.github.com/repos/basvanbeek/kit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/basvanbeek/kit/labels{/name}","releases_url":"https://api.github.com/repos/basvanbeek/kit/releases{/id}","deployments_url":"https://api.github.com/repos/basvanbeek/kit/deployments","created_at":"2015-06-26T14:59:44Z","updated_at":"2016-01-14T10:40:02Z","pushed_at":"2016-02-15T13:45:00Z","git_url":"git://github.com/basvanbeek/kit.git","ssh_url":"git@github.com:basvanbeek/kit.git","clone_url":"https://github.com/basvanbeek/kit.git","svn_url":"https://github.com/basvanbeek/kit","homepage":"http://gokit.io","size":4490,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"go-kit:master","ref":"master","sha":"724fee9497e9788bf00911ea5b2f4cfaf726bf3f","user":{"login":"go-kit","id":10981023,"avatar_url":"https://avatars.githubusercontent.com/u/10981023?v=3","gravatar_id":"","url":"https://api.github.com/users/go-kit","html_url":"https://github.com/go-kit","followers_url":"https://api.github.com/users/go-kit/followers","following_url":"https://api.github.com/users/go-kit/following{/other_user}","gists_url":"https://api.github.com/users/go-kit/gists{/gist_id}","starred_url":"https://api.github.com/users/go-kit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/go-kit/subscriptions","organizations_url":"https://api.github.com/users/go-kit/orgs","repos_url":"https://api.github.com/users/go-kit/repos","events_url":"https://api.github.com/users/go-kit/events{/privacy}","received_events_url":"https://api.github.com/users/go-kit/received_events","type":"Organization","site_admin":false},"repo":{"id":30215630,"name":"kit","full_name":"go-kit/kit","owner":{"login":"go-kit","id":10981023,"avatar_url":"https://avatars.githubusercontent.com/u/10981023?v=3","gravatar_id":"","url":"https://api.github.com/users/go-kit","html_url":"https://github.com/go-kit","followers_url":"https://api.github.com/users/go-kit/followers","following_url":"https://api.github.com/users/go-kit/following{/other_user}","gists_url":"https://api.github.com/users/go-kit/gists{/gist_id}","starred_url":"https://api.github.com/users/go-kit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/go-kit/subscriptions","organizations_url":"https://api.github.com/users/go-kit/orgs","repos_url":"https://api.github.com/users/go-kit/repos","events_url":"https://api.github.com/users/go-kit/events{/privacy}","received_events_url":"https://api.github.com/users/go-kit/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/go-kit/kit","description":"A standard library for microservices.","fork":false,"url":"https://api.github.com/repos/go-kit/kit","forks_url":"https://api.github.com/repos/go-kit/kit/forks","keys_url":"https://api.github.com/repos/go-kit/kit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/go-kit/kit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/go-kit/kit/teams","hooks_url":"https://api.github.com/repos/go-kit/kit/hooks","issue_events_url":"https://api.github.com/repos/go-kit/kit/issues/events{/number}","events_url":"https://api.github.com/repos/go-kit/kit/events","assignees_url":"https://api.github.com/repos/go-kit/kit/assignees{/user}","branches_url":"https://api.github.com/repos/go-kit/kit/branches{/branch}","tags_url":"https://api.github.com/repos/go-kit/kit/tags","blobs_url":"https://api.github.com/repos/go-kit/kit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/go-kit/kit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/go-kit/kit/git/refs{/sha}","trees_url":"https://api.github.com/repos/go-kit/kit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/go-kit/kit/statuses/{sha}","languages_url":"https://api.github.com/repos/go-kit/kit/languages","stargazers_url":"https://api.github.com/repos/go-kit/kit/stargazers","contributors_url":"https://api.github.com/repos/go-kit/kit/contributors","subscribers_url":"https://api.github.com/repos/go-kit/kit/subscribers","subscription_url":"https://api.github.com/repos/go-kit/kit/subscription","commits_url":"https://api.github.com/repos/go-kit/kit/commits{/sha}","git_commits_url":"https://api.github.com/repos/go-kit/kit/git/commits{/sha}","comments_url":"https://api.github.com/repos/go-kit/kit/comments{/number}","issue_comment_url":"https://api.github.com/repos/go-kit/kit/issues/comments{/number}","contents_url":"https://api.github.com/repos/go-kit/kit/contents/{+path}","compare_url":"https://api.github.com/repos/go-kit/kit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/go-kit/kit/merges","archive_url":"https://api.github.com/repos/go-kit/kit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/go-kit/kit/downloads","issues_url":"https://api.github.com/repos/go-kit/kit/issues{/number}","pulls_url":"https://api.github.com/repos/go-kit/kit/pulls{/number}","milestones_url":"https://api.github.com/repos/go-kit/kit/milestones{/number}","notifications_url":"https://api.github.com/repos/go-kit/kit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/go-kit/kit/labels{/name}","releases_url":"https://api.github.com/repos/go-kit/kit/releases{/id}","deployments_url":"https://api.github.com/repos/go-kit/kit/deployments","created_at":"2015-02-03T00:01:19Z","updated_at":"2016-02-18T18:58:46Z","pushed_at":"2016-02-15T13:45:01Z","git_url":"git://github.com/go-kit/kit.git","ssh_url":"git@github.com:go-kit/kit.git","clone_url":"https://github.com/go-kit/kit.git","svn_url":"https://github.com/go-kit/kit","homepage":"http://gokit.io","size":7450,"stargazers_count":3146,"watchers_count":3146,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":222,"mirror_url":null,"open_issues_count":19,"forks":222,"open_issues":19,"watchers":3146,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/go-kit/kit/pulls/195"},"html":{"href":"https://github.com/go-kit/kit/pull/195"},"issue":{"href":"https://api.github.com/repos/go-kit/kit/issues/195"},"comments":{"href":"https://api.github.com/repos/go-kit/kit/issues/195/comments"},"review_comments":{"href":"https://api.github.com/repos/go-kit/kit/pulls/195/comments"},"review_comment":{"href":"https://api.github.com/repos/go-kit/kit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/go-kit/kit/pulls/195/commits"},"statuses":{"href":"https://api.github.com/repos/go-kit/kit/statuses/1f495fdef67e1edc2d423c41686b1f858d8d8c25"}}}}