{"action":"created","comment":{"url":"https://api.github.com/repos/jbenet/go-ipfs/pulls/comments/25777193","id":25777193,"diff_hunk":"@@ -0,0 +1,106 @@\n+// pollEndpoint is a helper utility that waits for a http endpoint to be reachable and return with http.StatusOK\n+package main\n+\n+import (\n+\t\"flag\"\n+\t\"net\"\n+\t\"net/http\"\n+\t\"net/url\"\n+\t\"os\"\n+\t\"syscall\"\n+\t\"time\"\n+\n+\tlog \"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/Sirupsen/logrus\"\n+\tma \"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr\"\n+\tmanet \"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net\"\n+)\n+\n+var (\n+\thost     = flag.String(\"host\", \"/ip4/127.0.0.1/tcp/5001\", \"the multiaddr host to dial on\")\n+\tendpoint = flag.String(\"ep\", \"/version\", \"which http endpoint path to hit\")\n+\ttries    = flag.Int(\"tries\", 10, \"how many tries to make before failing\")\n+\ttimeout  = flag.Duration(\"tout\", time.Second, \"how long to wait between attempts\")\n+\tverbose  = flag.Bool(\"v\", false, \"verbose logging\")\n+)\n+\n+func main() {\n+\tflag.Parse()\n+\n+\t// extract address from host flag\n+\taddr, err := ma.NewMultiaddr(*host)\n+\tif err != nil {\n+\t\tlog.WithField(\"err\", err).Fatal(\"NewMultiaddr() failed\")\n+\t}\n+\tp := addr.Protocols()\n+\tif len(p) < 2 {\n+\t\tlog.WithField(\"addr\", addr).Fatal(\"need to protocolls in host flag.\")\n+\t}\n+\t_, host, err := manet.DialArgs(addr)\n+\tif err != nil {\n+\t\tlog.WithField(\"err\", err).Fatal(\"manet.DialArgs() failed\")\n+\t}\n+\n+\tif *verbose { // lower log level\n+\t\tlog.SetLevel(log.DebugLevel)\n+\t}\n+\n+\t// construct url to dial\n+\tvar u url.URL\n+\tu.Scheme = \"http\"\n+\tu.Host = host\n+\tu.Path = *endpoint\n+\n+\t// show what we got\n+\tstart := time.Now()\n+\tlog.WithFields(log.Fields{\n+\t\t\"when\":    start,\n+\t\t\"tries\":   *tries,\n+\t\t\"timeout\": *timeout,\n+\t\t\"url\":     u.String(),\n+\t}).Debug(\"starting\")\n+\n+\tfor *tries > 0 {\n+\n+\t\tf := log.Fields{\"tries\": *tries}\n+\n+\t\tresp, err := http.Get(u.String())\n+\n+\t\tif err == nil {\n+\t\t\tresp.Body.Close()\n+\n+\t\t\tif resp.StatusCode == http.StatusOK {\n+\t\t\t\tf[\"took\"] = time.Since(start)\n+\t\t\t\tlog.WithFields(f).Println(\"status ok - endpoint reachable\")\n+\t\t\t\tos.Exit(0)","path":"cmd/pollEndpoint/main.go","position":74,"original_position":74,"commit_id":"aa745fef07056bc25cf4759bfff9ab1a6ef11a5d","original_commit_id":"aa745fef07056bc25cf4759bfff9ab1a6ef11a5d","user":{"login":"jbenet","id":138401,"avatar_url":"https://avatars.githubusercontent.com/u/138401?v=3","gravatar_id":"","url":"https://api.github.com/users/jbenet","html_url":"https://github.com/jbenet","followers_url":"https://api.github.com/users/jbenet/followers","following_url":"https://api.github.com/users/jbenet/following{/other_user}","gists_url":"https://api.github.com/users/jbenet/gists{/gist_id}","starred_url":"https://api.github.com/users/jbenet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbenet/subscriptions","organizations_url":"https://api.github.com/users/jbenet/orgs","repos_url":"https://api.github.com/users/jbenet/repos","events_url":"https://api.github.com/users/jbenet/events{/privacy}","received_events_url":"https://api.github.com/users/jbenet/received_events","type":"User","site_admin":false},"body":"i'd try to return out to a simple func like:\r\n\r\n```go\r\nfunc main() { \r\n  if err := run(); err != nil {\r\n    log.Println(\"failed.\")\r\n    os.Exit(1)\r\n  }\r\n}\r\n```","created_at":"2015-03-04T14:23:06Z","updated_at":"2015-03-04T14:23:06Z","html_url":"https://github.com/jbenet/go-ipfs/pull/851#discussion_r25777193","pull_request_url":"https://api.github.com/repos/jbenet/go-ipfs/pulls/851","_links":{"self":{"href":"https://api.github.com/repos/jbenet/go-ipfs/pulls/comments/25777193"},"html":{"href":"https://github.com/jbenet/go-ipfs/pull/851#discussion_r25777193"},"pull_request":{"href":"https://api.github.com/repos/jbenet/go-ipfs/pulls/851"}}},"pull_request":{"url":"https://api.github.com/repos/jbenet/go-ipfs/pulls/851","id":30468183,"html_url":"https://github.com/jbenet/go-ipfs/pull/851","diff_url":"https://github.com/jbenet/go-ipfs/pull/851.diff","patch_url":"https://github.com/jbenet/go-ipfs/pull/851.patch","issue_url":"https://api.github.com/repos/jbenet/go-ipfs/issues/851","number":851,"state":"open","locked":false,"title":"Test/poll daemon","user":{"login":"cryptix","id":111202,"avatar_url":"https://avatars.githubusercontent.com/u/111202?v=3","gravatar_id":"","url":"https://api.github.com/users/cryptix","html_url":"https://github.com/cryptix","followers_url":"https://api.github.com/users/cryptix/followers","following_url":"https://api.github.com/users/cryptix/following{/other_user}","gists_url":"https://api.github.com/users/cryptix/gists{/gist_id}","starred_url":"https://api.github.com/users/cryptix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cryptix/subscriptions","organizations_url":"https://api.github.com/users/cryptix/orgs","repos_url":"https://api.github.com/users/cryptix/repos","events_url":"https://api.github.com/users/cryptix/events{/privacy}","received_events_url":"https://api.github.com/users/cryptix/received_events","type":"User","site_admin":false},"body":"In the quest for more stable tests (#844) we also want a better way to notice when the daemon is ready to accept http requests.\r\n\r\nPreviously we had a sleep/grep construction. This uses a small go program that polls an endpoint and returns with exit code zero when it returns `http 200 ok`","created_at":"2015-03-04T14:16:08Z","updated_at":"2015-03-04T14:23:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b8f2eb8d0fe1fae2651542a9299f581f12bb11fc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jbenet/go-ipfs/pulls/851/commits","review_comments_url":"https://api.github.com/repos/jbenet/go-ipfs/pulls/851/comments","review_comment_url":"https://api.github.com/repos/jbenet/go-ipfs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jbenet/go-ipfs/issues/851/comments","statuses_url":"https://api.github.com/repos/jbenet/go-ipfs/statuses/aa745fef07056bc25cf4759bfff9ab1a6ef11a5d","head":{"label":"jbenet:test/pollDaemon","ref":"test/pollDaemon","sha":"aa745fef07056bc25cf4759bfff9ab1a6ef11a5d","user":{"login":"jbenet","id":138401,"avatar_url":"https://avatars.githubusercontent.com/u/138401?v=3","gravatar_id":"","url":"https://api.github.com/users/jbenet","html_url":"https://github.com/jbenet","followers_url":"https://api.github.com/users/jbenet/followers","following_url":"https://api.github.com/users/jbenet/following{/other_user}","gists_url":"https://api.github.com/users/jbenet/gists{/gist_id}","starred_url":"https://api.github.com/users/jbenet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbenet/subscriptions","organizations_url":"https://api.github.com/users/jbenet/orgs","repos_url":"https://api.github.com/users/jbenet/repos","events_url":"https://api.github.com/users/jbenet/events{/privacy}","received_events_url":"https://api.github.com/users/jbenet/received_events","type":"User","site_admin":false},"repo":{"id":21233191,"name":"go-ipfs","full_name":"jbenet/go-ipfs","owner":{"login":"jbenet","id":138401,"avatar_url":"https://avatars.githubusercontent.com/u/138401?v=3","gravatar_id":"","url":"https://api.github.com/users/jbenet","html_url":"https://github.com/jbenet","followers_url":"https://api.github.com/users/jbenet/followers","following_url":"https://api.github.com/users/jbenet/following{/other_user}","gists_url":"https://api.github.com/users/jbenet/gists{/gist_id}","starred_url":"https://api.github.com/users/jbenet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbenet/subscriptions","organizations_url":"https://api.github.com/users/jbenet/orgs","repos_url":"https://api.github.com/users/jbenet/repos","events_url":"https://api.github.com/users/jbenet/events{/privacy}","received_events_url":"https://api.github.com/users/jbenet/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jbenet/go-ipfs","description":"ipfs implementation in go","fork":false,"url":"https://api.github.com/repos/jbenet/go-ipfs","forks_url":"https://api.github.com/repos/jbenet/go-ipfs/forks","keys_url":"https://api.github.com/repos/jbenet/go-ipfs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jbenet/go-ipfs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jbenet/go-ipfs/teams","hooks_url":"https://api.github.com/repos/jbenet/go-ipfs/hooks","issue_events_url":"https://api.github.com/repos/jbenet/go-ipfs/issues/events{/number}","events_url":"https://api.github.com/repos/jbenet/go-ipfs/events","assignees_url":"https://api.github.com/repos/jbenet/go-ipfs/assignees{/user}","branches_url":"https://api.github.com/repos/jbenet/go-ipfs/branches{/branch}","tags_url":"https://api.github.com/repos/jbenet/go-ipfs/tags","blobs_url":"https://api.github.com/repos/jbenet/go-ipfs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jbenet/go-ipfs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jbenet/go-ipfs/git/refs{/sha}","trees_url":"https://api.github.com/repos/jbenet/go-ipfs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jbenet/go-ipfs/statuses/{sha}","languages_url":"https://api.github.com/repos/jbenet/go-ipfs/languages","stargazers_url":"https://api.github.com/repos/jbenet/go-ipfs/stargazers","contributors_url":"https://api.github.com/repos/jbenet/go-ipfs/contributors","subscribers_url":"https://api.github.com/repos/jbenet/go-ipfs/subscribers","subscription_url":"https://api.github.com/repos/jbenet/go-ipfs/subscription","commits_url":"https://api.github.com/repos/jbenet/go-ipfs/commits{/sha}","git_commits_url":"https://api.github.com/repos/jbenet/go-ipfs/git/commits{/sha}","comments_url":"https://api.github.com/repos/jbenet/go-ipfs/comments{/number}","issue_comment_url":"https://api.github.com/repos/jbenet/go-ipfs/issues/comments{/number}","contents_url":"https://api.github.com/repos/jbenet/go-ipfs/contents/{+path}","compare_url":"https://api.github.com/repos/jbenet/go-ipfs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jbenet/go-ipfs/merges","archive_url":"https://api.github.com/repos/jbenet/go-ipfs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jbenet/go-ipfs/downloads","issues_url":"https://api.github.com/repos/jbenet/go-ipfs/issues{/number}","pulls_url":"https://api.github.com/repos/jbenet/go-ipfs/pulls{/number}","milestones_url":"https://api.github.com/repos/jbenet/go-ipfs/milestones{/number}","notifications_url":"https://api.github.com/repos/jbenet/go-ipfs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jbenet/go-ipfs/labels{/name}","releases_url":"https://api.github.com/repos/jbenet/go-ipfs/releases{/id}","created_at":"2014-06-26T08:14:34Z","updated_at":"2015-03-04T04:06:57Z","pushed_at":"2015-03-04T14:06:30Z","git_url":"git://github.com/jbenet/go-ipfs.git","ssh_url":"git@github.com:jbenet/go-ipfs.git","clone_url":"https://github.com/jbenet/go-ipfs.git","svn_url":"https://github.com/jbenet/go-ipfs","homepage":"https://github.com/jbenet/ipfs","size":29325,"stargazers_count":328,"watchers_count":328,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":44,"mirror_url":null,"open_issues_count":175,"forks":44,"open_issues":175,"watchers":328,"default_branch":"master"}},"base":{"label":"jbenet:master","ref":"master","sha":"51a8bcbf64846ee081118b1c8e685b2a687b46cc","user":{"login":"jbenet","id":138401,"avatar_url":"https://avatars.githubusercontent.com/u/138401?v=3","gravatar_id":"","url":"https://api.github.com/users/jbenet","html_url":"https://github.com/jbenet","followers_url":"https://api.github.com/users/jbenet/followers","following_url":"https://api.github.com/users/jbenet/following{/other_user}","gists_url":"https://api.github.com/users/jbenet/gists{/gist_id}","starred_url":"https://api.github.com/users/jbenet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbenet/subscriptions","organizations_url":"https://api.github.com/users/jbenet/orgs","repos_url":"https://api.github.com/users/jbenet/repos","events_url":"https://api.github.com/users/jbenet/events{/privacy}","received_events_url":"https://api.github.com/users/jbenet/received_events","type":"User","site_admin":false},"repo":{"id":21233191,"name":"go-ipfs","full_name":"jbenet/go-ipfs","owner":{"login":"jbenet","id":138401,"avatar_url":"https://avatars.githubusercontent.com/u/138401?v=3","gravatar_id":"","url":"https://api.github.com/users/jbenet","html_url":"https://github.com/jbenet","followers_url":"https://api.github.com/users/jbenet/followers","following_url":"https://api.github.com/users/jbenet/following{/other_user}","gists_url":"https://api.github.com/users/jbenet/gists{/gist_id}","starred_url":"https://api.github.com/users/jbenet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbenet/subscriptions","organizations_url":"https://api.github.com/users/jbenet/orgs","repos_url":"https://api.github.com/users/jbenet/repos","events_url":"https://api.github.com/users/jbenet/events{/privacy}","received_events_url":"https://api.github.com/users/jbenet/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jbenet/go-ipfs","description":"ipfs implementation in go","fork":false,"url":"https://api.github.com/repos/jbenet/go-ipfs","forks_url":"https://api.github.com/repos/jbenet/go-ipfs/forks","keys_url":"https://api.github.com/repos/jbenet/go-ipfs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jbenet/go-ipfs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jbenet/go-ipfs/teams","hooks_url":"https://api.github.com/repos/jbenet/go-ipfs/hooks","issue_events_url":"https://api.github.com/repos/jbenet/go-ipfs/issues/events{/number}","events_url":"https://api.github.com/repos/jbenet/go-ipfs/events","assignees_url":"https://api.github.com/repos/jbenet/go-ipfs/assignees{/user}","branches_url":"https://api.github.com/repos/jbenet/go-ipfs/branches{/branch}","tags_url":"https://api.github.com/repos/jbenet/go-ipfs/tags","blobs_url":"https://api.github.com/repos/jbenet/go-ipfs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jbenet/go-ipfs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jbenet/go-ipfs/git/refs{/sha}","trees_url":"https://api.github.com/repos/jbenet/go-ipfs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jbenet/go-ipfs/statuses/{sha}","languages_url":"https://api.github.com/repos/jbenet/go-ipfs/languages","stargazers_url":"https://api.github.com/repos/jbenet/go-ipfs/stargazers","contributors_url":"https://api.github.com/repos/jbenet/go-ipfs/contributors","subscribers_url":"https://api.github.com/repos/jbenet/go-ipfs/subscribers","subscription_url":"https://api.github.com/repos/jbenet/go-ipfs/subscription","commits_url":"https://api.github.com/repos/jbenet/go-ipfs/commits{/sha}","git_commits_url":"https://api.github.com/repos/jbenet/go-ipfs/git/commits{/sha}","comments_url":"https://api.github.com/repos/jbenet/go-ipfs/comments{/number}","issue_comment_url":"https://api.github.com/repos/jbenet/go-ipfs/issues/comments{/number}","contents_url":"https://api.github.com/repos/jbenet/go-ipfs/contents/{+path}","compare_url":"https://api.github.com/repos/jbenet/go-ipfs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jbenet/go-ipfs/merges","archive_url":"https://api.github.com/repos/jbenet/go-ipfs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jbenet/go-ipfs/downloads","issues_url":"https://api.github.com/repos/jbenet/go-ipfs/issues{/number}","pulls_url":"https://api.github.com/repos/jbenet/go-ipfs/pulls{/number}","milestones_url":"https://api.github.com/repos/jbenet/go-ipfs/milestones{/number}","notifications_url":"https://api.github.com/repos/jbenet/go-ipfs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jbenet/go-ipfs/labels{/name}","releases_url":"https://api.github.com/repos/jbenet/go-ipfs/releases{/id}","created_at":"2014-06-26T08:14:34Z","updated_at":"2015-03-04T04:06:57Z","pushed_at":"2015-03-04T14:06:30Z","git_url":"git://github.com/jbenet/go-ipfs.git","ssh_url":"git@github.com:jbenet/go-ipfs.git","clone_url":"https://github.com/jbenet/go-ipfs.git","svn_url":"https://github.com/jbenet/go-ipfs","homepage":"https://github.com/jbenet/ipfs","size":29325,"stargazers_count":328,"watchers_count":328,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":44,"mirror_url":null,"open_issues_count":175,"forks":44,"open_issues":175,"watchers":328,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jbenet/go-ipfs/pulls/851"},"html":{"href":"https://github.com/jbenet/go-ipfs/pull/851"},"issue":{"href":"https://api.github.com/repos/jbenet/go-ipfs/issues/851"},"comments":{"href":"https://api.github.com/repos/jbenet/go-ipfs/issues/851/comments"},"review_comments":{"href":"https://api.github.com/repos/jbenet/go-ipfs/pulls/851/comments"},"review_comment":{"href":"https://api.github.com/repos/jbenet/go-ipfs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jbenet/go-ipfs/pulls/851/commits"},"statuses":{"href":"https://api.github.com/repos/jbenet/go-ipfs/statuses/aa745fef07056bc25cf4759bfff9ab1a6ef11a5d"}}}}