{"action":"created","comment":{"url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/pulls/comments/79109215","id":79109215,"diff_hunk":"@@ -0,0 +1,81 @@\n+// Copyright 2016 Google Inc. All rights reserved.\n+// Use of this source code is governed by the Apache 2.0\n+// license that can be found in the LICENSE file.\n+\n+package testutil\n+\n+import (\n+\t\"bytes\"\n+\t\"fmt\"\n+\t\"path/filepath\"\n+\t\"runtime\"\n+\t\"strconv\"\n+\t\"testing\"\n+\t\"time\"\n+)\n+\n+// Flaky runs function f for up to maxAttempts times until f returns successfully, and reports whether f was run successfully.\n+// It will sleep for the given period between invocations of f.\n+// Use the provided *testutil.R instead of a *testing.T from the function.\n+func Flaky(t *testing.T, maxAttempts int, sleep time.Duration, f func(r *R)) bool {\n+\tfor attempt := 1; attempt <= maxAttempts; attempt++ {\n+\t\tr := &R{Attempt: attempt, log: &bytes.Buffer{}}\n+\n+\t\tf(r)\n+\n+\t\tif !r.failed {\n+\t\t\tif r.log.Len() != 0 {\n+\t\t\t\tt.Logf(\"Success after %d attempts:%s\", attempt, r.log.String())\n+\t\t\t}\n+\t\t\treturn true\n+\t\t}\n+\n+\t\tif attempt == maxAttempts {\n+\t\t\tt.Logf(\"FAILED after %d attempts:%s\", attempt, r.log.String())","path":"internal/testutil/retry.go","position":34,"original_position":34,"commit_id":"e4bd9f698ffe393c99b740d2c6a9d1388d07eeaa","original_commit_id":"e4bd9f698ffe393c99b740d2c6a9d1388d07eeaa","user":{"login":"okdave","id":1091335,"avatar_url":"https://avatars.githubusercontent.com/u/1091335?v=3","gravatar_id":"","url":"https://api.github.com/users/okdave","html_url":"https://github.com/okdave","followers_url":"https://api.github.com/users/okdave/followers","following_url":"https://api.github.com/users/okdave/following{/other_user}","gists_url":"https://api.github.com/users/okdave/gists{/gist_id}","starred_url":"https://api.github.com/users/okdave/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/okdave/subscriptions","organizations_url":"https://api.github.com/users/okdave/orgs","repos_url":"https://api.github.com/users/okdave/repos","events_url":"https://api.github.com/users/okdave/events{/privacy}","received_events_url":"https://api.github.com/users/okdave/received_events","type":"User","site_admin":false},"body":"Should you keep the original log lines (as a slice?) so you can actually replay these as errors/logs directly on T?","created_at":"2016-09-16T05:41:08Z","updated_at":"2016-09-16T05:42:10Z","html_url":"https://github.com/GoogleCloudPlatform/golang-samples/pull/116#discussion_r79109215","pull_request_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/pulls/116","_links":{"self":{"href":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/pulls/comments/79109215"},"html":{"href":"https://github.com/GoogleCloudPlatform/golang-samples/pull/116#discussion_r79109215"},"pull_request":{"href":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/pulls/116"}}},"pull_request":{"url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/pulls/116","id":85154321,"html_url":"https://github.com/GoogleCloudPlatform/golang-samples/pull/116","diff_url":"https://github.com/GoogleCloudPlatform/golang-samples/pull/116.diff","patch_url":"https://github.com/GoogleCloudPlatform/golang-samples/pull/116.patch","issue_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/issues/116","number":116,"state":"open","locked":false,"title":"all: add retry support for flaky tests","user":{"login":"broady","id":24982,"avatar_url":"https://avatars.githubusercontent.com/u/24982?v=3","gravatar_id":"","url":"https://api.github.com/users/broady","html_url":"https://github.com/broady","followers_url":"https://api.github.com/users/broady/followers","following_url":"https://api.github.com/users/broady/following{/other_user}","gists_url":"https://api.github.com/users/broady/gists{/gist_id}","starred_url":"https://api.github.com/users/broady/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broady/subscriptions","organizations_url":"https://api.github.com/users/broady/orgs","repos_url":"https://api.github.com/users/broady/repos","events_url":"https://api.github.com/users/broady/events{/privacy}","received_events_url":"https://api.github.com/users/broady/received_events","type":"User","site_admin":false},"body":"Test output is only written for the final attempt.\r\n\r\nA similar interface to *testing.T is provided to each attempt.\r\n\r\n```\r\n$ go test -v ./internal/testutil/\r\n=== RUN   TestRetry\r\n--- PASS: TestRetry (0.00s)\r\n=== RUN   TestRetryAttempts\r\n--- PASS: TestRetryAttempts (0.00s)\r\n\tretry.go:29: Success after 5 attempts:\r\n\t\tretry_test.go:24: This line should appear only once.\r\n\t\tretry_test.go:25: attempt=5\r\nPASS\r\nok  \tgithub.com/GoogleCloudPlatform/golang-samples/internal/testutil\t0.023s\r\n```","created_at":"2016-09-14T01:44:02Z","updated_at":"2016-09-16T05:42:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"731017c2bd2d5b4861334c85629b6868feb2925f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/pulls/116/commits","review_comments_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/pulls/116/comments","review_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/issues/116/comments","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/statuses/e4bd9f698ffe393c99b740d2c6a9d1388d07eeaa","head":{"label":"GoogleCloudPlatform:retry","ref":"retry","sha":"e4bd9f698ffe393c99b740d2c6a9d1388d07eeaa","user":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"repo":{"id":43332504,"name":"golang-samples","full_name":"GoogleCloudPlatform/golang-samples","owner":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleCloudPlatform/golang-samples","description":"Sample apps and code written in the Go programming language.","fork":false,"url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples","forks_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/forks","keys_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/teams","hooks_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/hooks","issue_events_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/events","assignees_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/tags","blobs_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/languages","stargazers_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/stargazers","contributors_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/contributors","subscribers_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/subscribers","subscription_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/subscription","commits_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/merges","archive_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/downloads","issues_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/labels{/name}","releases_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/releases{/id}","deployments_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/deployments","created_at":"2015-09-28T23:20:08Z","updated_at":"2016-09-12T15:52:24Z","pushed_at":"2016-09-16T05:34:52Z","git_url":"git://github.com/GoogleCloudPlatform/golang-samples.git","ssh_url":"git@github.com:GoogleCloudPlatform/golang-samples.git","clone_url":"https://github.com/GoogleCloudPlatform/golang-samples.git","svn_url":"https://github.com/GoogleCloudPlatform/golang-samples","homepage":null,"size":671,"stargazers_count":99,"watchers_count":99,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":35,"mirror_url":null,"open_issues_count":18,"forks":35,"open_issues":18,"watchers":99,"default_branch":"master"}},"base":{"label":"GoogleCloudPlatform:master","ref":"master","sha":"b5f7a025804e34e9721b8082386a40af86b81b85","user":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"repo":{"id":43332504,"name":"golang-samples","full_name":"GoogleCloudPlatform/golang-samples","owner":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleCloudPlatform/golang-samples","description":"Sample apps and code written in the Go programming language.","fork":false,"url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples","forks_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/forks","keys_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/teams","hooks_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/hooks","issue_events_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/events","assignees_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/tags","blobs_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/languages","stargazers_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/stargazers","contributors_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/contributors","subscribers_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/subscribers","subscription_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/subscription","commits_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/merges","archive_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/downloads","issues_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/labels{/name}","releases_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/releases{/id}","deployments_url":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/deployments","created_at":"2015-09-28T23:20:08Z","updated_at":"2016-09-12T15:52:24Z","pushed_at":"2016-09-16T05:34:52Z","git_url":"git://github.com/GoogleCloudPlatform/golang-samples.git","ssh_url":"git@github.com:GoogleCloudPlatform/golang-samples.git","clone_url":"https://github.com/GoogleCloudPlatform/golang-samples.git","svn_url":"https://github.com/GoogleCloudPlatform/golang-samples","homepage":null,"size":671,"stargazers_count":99,"watchers_count":99,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":35,"mirror_url":null,"open_issues_count":18,"forks":35,"open_issues":18,"watchers":99,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/pulls/116"},"html":{"href":"https://github.com/GoogleCloudPlatform/golang-samples/pull/116"},"issue":{"href":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/issues/116"},"comments":{"href":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/issues/116/comments"},"review_comments":{"href":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/pulls/116/comments"},"review_comment":{"href":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/pulls/116/commits"},"statuses":{"href":"https://api.github.com/repos/GoogleCloudPlatform/golang-samples/statuses/e4bd9f698ffe393c99b740d2c6a9d1388d07eeaa"}}}}
{"actor":{"display_login":"okdave"}}