{"action":"created","comment":{"url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/comments/57740728","id":57740728,"diff_hunk":"@@ -34,204 +35,291 @@ type taskRunnerSuite struct{}\n \n var _ = Suite(&taskRunnerSuite{})\n \n-func (ts *taskRunnerSuite) TestEnsureTrivial(c *C) {\n-\tst := state.New(nil)\n-\n-\t// setup the download handler\n-\ttaskCompleted := sync.WaitGroup{}\n-\tr := state.NewTaskRunner(st)\n-\tfn := func(task *state.Task, tomb *tomb.Tomb) error {\n-\t\ttask.State().Lock()\n-\t\tdefer task.State().Unlock()\n-\t\tc.Check(task.Status(), Equals, state.DoStatus)\n-\t\ttaskCompleted.Done()\n-\t\treturn nil\n-\t}\n-\tr.AddHandler(\"download\", fn)\n-\n-\t// add a download task to the state tracker\n-\tst.Lock()\n-\tchg := st.NewChange(\"install\", \"...\")\n-\tt := st.NewTask(\"download\", \"1...\")\n-\tchg.AddTask(t)\n-\ttaskCompleted.Add(1)\n-\tst.Unlock()\n-\n-\tdefer r.Stop()\n-\n-\t// ensure just kicks the go routine off\n-\tr.Ensure()\n-\ttaskCompleted.Wait()\n-\n-\tst.Lock()\n-\tdefer st.Unlock()\n-\tc.Check(t.Status(), Equals, state.DoneStatus)\n-}\n-\n type stateBackend struct {\n-\trunner *state.TaskRunner\n+\tmu           sync.Mutex\n+\tensureBefore time.Duration\n }\n \n-func (b *stateBackend) Checkpoint([]byte) error {\n-\treturn nil\n-}\n+func (b *stateBackend) Checkpoint([]byte) error { return nil }\n \n func (b *stateBackend) EnsureBefore(d time.Duration) {\n-\tgo b.runner.Ensure()\n-}\n-\n-func (ts *taskRunnerSuite) TestEnsureComplex(c *C) {\n-\tb := &stateBackend{}\n-\tst := state.New(b)\n-\n-\tr := state.NewTaskRunner(st)\n-\tb.runner = r\n-\n-\t// setup handlers\n-\torderingCh := make(chan string, 3)\n-\tfn := func(task *state.Task, tomb *tomb.Tomb) error {\n-\t\ttask.State().Lock()\n-\t\tdefer task.State().Unlock()\n-\t\tc.Check(task.Status(), Equals, state.DoStatus)\n-\t\torderingCh <- task.Kind()\n-\t\treturn nil\n+\tb.mu.Lock()\n+\tif d < b.ensureBefore {\n+\t\tb.ensureBefore = d\n \t}\n-\tr.AddHandler(\"download\", fn)\n-\tr.AddHandler(\"unpack\", fn)\n-\tr.AddHandler(\"configure\", fn)\n-\n-\tdefer r.Stop()\n-\n-\t// run in a loop to ensure ordering is not correct by pure chance\n-\tfor i := 0; i < 100; i++ {\n-\t\tst.Lock()\n-\t\tchg := st.NewChange(\"mock-install\", \"...\")\n-\n-\t\t// create sub-tasks\n-\t\ttDl := st.NewTask(\"download\", \"1...\")\n-\t\ttUnp := st.NewTask(\"unpack\", \"2...\")\n-\t\ttUnp.WaitFor(tDl)\n-\t\tchg.AddAll(state.NewTaskSet(tDl, tUnp))\n-\t\ttConf := st.NewTask(\"configure\", \"3...\")\n-\t\ttConf.WaitFor(tUnp)\n-\t\tchg.AddAll(state.NewTaskSet(tConf))\n-\t\tst.Unlock()\n+\tb.mu.Unlock()\n+}\n \n-\t\t// ensure just kicks the go routine off\n-\t\t// and then they get scheduled as they finish\n+func ensureChange(c *C, r *state.TaskRunner, sb *stateBackend, chg *state.Change) {\n+\tsb.ensureBefore = 0\n+\tfor sb.ensureBefore == 0 {","path":"overlord/state/taskrunner_test.go","position":107,"original_position":107,"commit_id":"1c1677db66a4e34aeda420a1aff4205f9f33a767","original_commit_id":"1c1677db66a4e34aeda420a1aff4205f9f33a767","user":{"login":"pedronis","id":975757,"avatar_url":"https://avatars.githubusercontent.com/u/975757?v=3","gravatar_id":"","url":"https://api.github.com/users/pedronis","html_url":"https://github.com/pedronis","followers_url":"https://api.github.com/users/pedronis/followers","following_url":"https://api.github.com/users/pedronis/following{/other_user}","gists_url":"https://api.github.com/users/pedronis/gists{/gist_id}","starred_url":"https://api.github.com/users/pedronis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedronis/subscriptions","organizations_url":"https://api.github.com/users/pedronis/orgs","repos_url":"https://api.github.com/users/pedronis/repos","events_url":"https://api.github.com/users/pedronis/events{/privacy}","received_events_url":"https://api.github.com/users/pedronis/received_events","type":"User","site_admin":false},"body":"I think here before Ensure() sb.ensureBefore should be set to something large to actually this not just be a Ensure loop again","created_at":"2016-03-29T15:13:03Z","updated_at":"2016-03-29T15:13:03Z","html_url":"https://github.com/ubuntu-core/snappy/pull/745#discussion_r57740728","pull_request_url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/745","_links":{"self":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/comments/57740728"},"html":{"href":"https://github.com/ubuntu-core/snappy/pull/745#discussion_r57740728"},"pull_request":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/745"}}},"pull_request":{"url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/745","id":64256711,"html_url":"https://github.com/ubuntu-core/snappy/pull/745","diff_url":"https://github.com/ubuntu-core/snappy/pull/745.diff","patch_url":"https://github.com/ubuntu-core/snappy/pull/745.patch","issue_url":"https://api.github.com/repos/ubuntu-core/snappy/issues/745","number":745,"state":"open","locked":false,"title":"overlord/state: support task undoing","user":{"login":"niemeyer","id":378683,"avatar_url":"https://avatars.githubusercontent.com/u/378683?v=3","gravatar_id":"","url":"https://api.github.com/users/niemeyer","html_url":"https://github.com/niemeyer","followers_url":"https://api.github.com/users/niemeyer/followers","following_url":"https://api.github.com/users/niemeyer/following{/other_user}","gists_url":"https://api.github.com/users/niemeyer/gists{/gist_id}","starred_url":"https://api.github.com/users/niemeyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niemeyer/subscriptions","organizations_url":"https://api.github.com/users/niemeyer/orgs","repos_url":"https://api.github.com/users/niemeyer/repos","events_url":"https://api.github.com/users/niemeyer/events{/privacy}","received_events_url":"https://api.github.com/users/niemeyer/received_events","type":"User","site_admin":false},"body":"This change introduces new statuses to track tasks in more detail, and implements support for registering a counterpart handler that is capable of undoing modifications that the task has previously made when performing the change.\r\n\r\nThe testing approach has also been improved, with a harness that is able to clearly and tersely define the a configuration for testing, and visualize the expected sequence of events that should come out of it.","created_at":"2016-03-27T04:03:16Z","updated_at":"2016-03-29T15:13:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dcde6a88b5a4e6d8f34b9e0790631ae7aab96c3b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/745/commits","review_comments_url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/745/comments","review_comment_url":"https://api.github.com/repos/ubuntu-core/snappy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ubuntu-core/snappy/issues/745/comments","statuses_url":"https://api.github.com/repos/ubuntu-core/snappy/statuses/1c1677db66a4e34aeda420a1aff4205f9f33a767","head":{"label":"niemeyer:task-undo","ref":"task-undo","sha":"1c1677db66a4e34aeda420a1aff4205f9f33a767","user":{"login":"niemeyer","id":378683,"avatar_url":"https://avatars.githubusercontent.com/u/378683?v=3","gravatar_id":"","url":"https://api.github.com/users/niemeyer","html_url":"https://github.com/niemeyer","followers_url":"https://api.github.com/users/niemeyer/followers","following_url":"https://api.github.com/users/niemeyer/following{/other_user}","gists_url":"https://api.github.com/users/niemeyer/gists{/gist_id}","starred_url":"https://api.github.com/users/niemeyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niemeyer/subscriptions","organizations_url":"https://api.github.com/users/niemeyer/orgs","repos_url":"https://api.github.com/users/niemeyer/repos","events_url":"https://api.github.com/users/niemeyer/events{/privacy}","received_events_url":"https://api.github.com/users/niemeyer/received_events","type":"User","site_admin":false},"repo":{"id":45629225,"name":"snappy","full_name":"niemeyer/snappy","owner":{"login":"niemeyer","id":378683,"avatar_url":"https://avatars.githubusercontent.com/u/378683?v=3","gravatar_id":"","url":"https://api.github.com/users/niemeyer","html_url":"https://github.com/niemeyer","followers_url":"https://api.github.com/users/niemeyer/followers","following_url":"https://api.github.com/users/niemeyer/following{/other_user}","gists_url":"https://api.github.com/users/niemeyer/gists{/gist_id}","starred_url":"https://api.github.com/users/niemeyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niemeyer/subscriptions","organizations_url":"https://api.github.com/users/niemeyer/orgs","repos_url":"https://api.github.com/users/niemeyer/repos","events_url":"https://api.github.com/users/niemeyer/events{/privacy}","received_events_url":"https://api.github.com/users/niemeyer/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/niemeyer/snappy","description":"Snappy is the software at the heart of Ubuntu Core.","fork":true,"url":"https://api.github.com/repos/niemeyer/snappy","forks_url":"https://api.github.com/repos/niemeyer/snappy/forks","keys_url":"https://api.github.com/repos/niemeyer/snappy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/niemeyer/snappy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/niemeyer/snappy/teams","hooks_url":"https://api.github.com/repos/niemeyer/snappy/hooks","issue_events_url":"https://api.github.com/repos/niemeyer/snappy/issues/events{/number}","events_url":"https://api.github.com/repos/niemeyer/snappy/events","assignees_url":"https://api.github.com/repos/niemeyer/snappy/assignees{/user}","branches_url":"https://api.github.com/repos/niemeyer/snappy/branches{/branch}","tags_url":"https://api.github.com/repos/niemeyer/snappy/tags","blobs_url":"https://api.github.com/repos/niemeyer/snappy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/niemeyer/snappy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/niemeyer/snappy/git/refs{/sha}","trees_url":"https://api.github.com/repos/niemeyer/snappy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/niemeyer/snappy/statuses/{sha}","languages_url":"https://api.github.com/repos/niemeyer/snappy/languages","stargazers_url":"https://api.github.com/repos/niemeyer/snappy/stargazers","contributors_url":"https://api.github.com/repos/niemeyer/snappy/contributors","subscribers_url":"https://api.github.com/repos/niemeyer/snappy/subscribers","subscription_url":"https://api.github.com/repos/niemeyer/snappy/subscription","commits_url":"https://api.github.com/repos/niemeyer/snappy/commits{/sha}","git_commits_url":"https://api.github.com/repos/niemeyer/snappy/git/commits{/sha}","comments_url":"https://api.github.com/repos/niemeyer/snappy/comments{/number}","issue_comment_url":"https://api.github.com/repos/niemeyer/snappy/issues/comments{/number}","contents_url":"https://api.github.com/repos/niemeyer/snappy/contents/{+path}","compare_url":"https://api.github.com/repos/niemeyer/snappy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/niemeyer/snappy/merges","archive_url":"https://api.github.com/repos/niemeyer/snappy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/niemeyer/snappy/downloads","issues_url":"https://api.github.com/repos/niemeyer/snappy/issues{/number}","pulls_url":"https://api.github.com/repos/niemeyer/snappy/pulls{/number}","milestones_url":"https://api.github.com/repos/niemeyer/snappy/milestones{/number}","notifications_url":"https://api.github.com/repos/niemeyer/snappy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/niemeyer/snappy/labels{/name}","releases_url":"https://api.github.com/repos/niemeyer/snappy/releases{/id}","deployments_url":"https://api.github.com/repos/niemeyer/snappy/deployments","created_at":"2015-11-05T17:56:14Z","updated_at":"2016-03-22T09:11:01Z","pushed_at":"2016-03-29T14:16:25Z","git_url":"git://github.com/niemeyer/snappy.git","ssh_url":"git@github.com:niemeyer/snappy.git","clone_url":"https://github.com/niemeyer/snappy.git","svn_url":"https://github.com/niemeyer/snappy","homepage":null,"size":26630,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"ubuntu-core:master","ref":"master","sha":"32fbe647fa1b84f3b9f2c4ea02ea64124536d155","user":{"login":"ubuntu-core","id":15022473,"avatar_url":"https://avatars.githubusercontent.com/u/15022473?v=3","gravatar_id":"","url":"https://api.github.com/users/ubuntu-core","html_url":"https://github.com/ubuntu-core","followers_url":"https://api.github.com/users/ubuntu-core/followers","following_url":"https://api.github.com/users/ubuntu-core/following{/other_user}","gists_url":"https://api.github.com/users/ubuntu-core/gists{/gist_id}","starred_url":"https://api.github.com/users/ubuntu-core/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubuntu-core/subscriptions","organizations_url":"https://api.github.com/users/ubuntu-core/orgs","repos_url":"https://api.github.com/users/ubuntu-core/repos","events_url":"https://api.github.com/users/ubuntu-core/events{/privacy}","received_events_url":"https://api.github.com/users/ubuntu-core/received_events","type":"Organization","site_admin":false},"repo":{"id":44672744,"name":"snappy","full_name":"ubuntu-core/snappy","owner":{"login":"ubuntu-core","id":15022473,"avatar_url":"https://avatars.githubusercontent.com/u/15022473?v=3","gravatar_id":"","url":"https://api.github.com/users/ubuntu-core","html_url":"https://github.com/ubuntu-core","followers_url":"https://api.github.com/users/ubuntu-core/followers","following_url":"https://api.github.com/users/ubuntu-core/following{/other_user}","gists_url":"https://api.github.com/users/ubuntu-core/gists{/gist_id}","starred_url":"https://api.github.com/users/ubuntu-core/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubuntu-core/subscriptions","organizations_url":"https://api.github.com/users/ubuntu-core/orgs","repos_url":"https://api.github.com/users/ubuntu-core/repos","events_url":"https://api.github.com/users/ubuntu-core/events{/privacy}","received_events_url":"https://api.github.com/users/ubuntu-core/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ubuntu-core/snappy","description":"Snappy is the software at the heart of Ubuntu Core.","fork":false,"url":"https://api.github.com/repos/ubuntu-core/snappy","forks_url":"https://api.github.com/repos/ubuntu-core/snappy/forks","keys_url":"https://api.github.com/repos/ubuntu-core/snappy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ubuntu-core/snappy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ubuntu-core/snappy/teams","hooks_url":"https://api.github.com/repos/ubuntu-core/snappy/hooks","issue_events_url":"https://api.github.com/repos/ubuntu-core/snappy/issues/events{/number}","events_url":"https://api.github.com/repos/ubuntu-core/snappy/events","assignees_url":"https://api.github.com/repos/ubuntu-core/snappy/assignees{/user}","branches_url":"https://api.github.com/repos/ubuntu-core/snappy/branches{/branch}","tags_url":"https://api.github.com/repos/ubuntu-core/snappy/tags","blobs_url":"https://api.github.com/repos/ubuntu-core/snappy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ubuntu-core/snappy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ubuntu-core/snappy/git/refs{/sha}","trees_url":"https://api.github.com/repos/ubuntu-core/snappy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ubuntu-core/snappy/statuses/{sha}","languages_url":"https://api.github.com/repos/ubuntu-core/snappy/languages","stargazers_url":"https://api.github.com/repos/ubuntu-core/snappy/stargazers","contributors_url":"https://api.github.com/repos/ubuntu-core/snappy/contributors","subscribers_url":"https://api.github.com/repos/ubuntu-core/snappy/subscribers","subscription_url":"https://api.github.com/repos/ubuntu-core/snappy/subscription","commits_url":"https://api.github.com/repos/ubuntu-core/snappy/commits{/sha}","git_commits_url":"https://api.github.com/repos/ubuntu-core/snappy/git/commits{/sha}","comments_url":"https://api.github.com/repos/ubuntu-core/snappy/comments{/number}","issue_comment_url":"https://api.github.com/repos/ubuntu-core/snappy/issues/comments{/number}","contents_url":"https://api.github.com/repos/ubuntu-core/snappy/contents/{+path}","compare_url":"https://api.github.com/repos/ubuntu-core/snappy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ubuntu-core/snappy/merges","archive_url":"https://api.github.com/repos/ubuntu-core/snappy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ubuntu-core/snappy/downloads","issues_url":"https://api.github.com/repos/ubuntu-core/snappy/issues{/number}","pulls_url":"https://api.github.com/repos/ubuntu-core/snappy/pulls{/number}","milestones_url":"https://api.github.com/repos/ubuntu-core/snappy/milestones{/number}","notifications_url":"https://api.github.com/repos/ubuntu-core/snappy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ubuntu-core/snappy/labels{/name}","releases_url":"https://api.github.com/repos/ubuntu-core/snappy/releases{/id}","deployments_url":"https://api.github.com/repos/ubuntu-core/snappy/deployments","created_at":"2015-10-21T11:51:46Z","updated_at":"2016-03-24T10:07:31Z","pushed_at":"2016-03-29T14:55:40Z","git_url":"git://github.com/ubuntu-core/snappy.git","ssh_url":"git@github.com:ubuntu-core/snappy.git","clone_url":"https://github.com/ubuntu-core/snappy.git","svn_url":"https://github.com/ubuntu-core/snappy","homepage":null,"size":27722,"stargazers_count":59,"watchers_count":59,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"open_issues_count":23,"forks":30,"open_issues":23,"watchers":59,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/745"},"html":{"href":"https://github.com/ubuntu-core/snappy/pull/745"},"issue":{"href":"https://api.github.com/repos/ubuntu-core/snappy/issues/745"},"comments":{"href":"https://api.github.com/repos/ubuntu-core/snappy/issues/745/comments"},"review_comments":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/745/comments"},"review_comment":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ubuntu-core/snappy/pulls/745/commits"},"statuses":{"href":"https://api.github.com/repos/ubuntu-core/snappy/statuses/1c1677db66a4e34aeda420a1aff4205f9f33a767"}}}}