{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/async_experiments/pulls/comments/78154688","id":78154688,"diff_hunk":"@@ -3,41 +3,48 @@\n require \"async_experiments\"\n \n RSpec.describe AsyncExperiments do\n+  let(:redis) do\n+    double(\n+      :redis,\n+      scan_each: nil,\n+      get: nil,\n+    )\n+  end\n+\n+  before do\n+    allow(Sidekiq).to receive(:redis).and_yield(redis)\n+  end\n+\n   describe \".get_experiment_data(experiment_name)\" do\n     let(:name) { \"some_experiment\" }\n \n-    let(:experiment_results) {\n-      [\n-        JSON.dump([\n-          [\"-\", \"[1]\", {same_key: 1, different_key: 2}],\n-          [\"+\", \"[2]\", {same_key: 1, different_key: 3}],\n-          [\"+\", \"[3]\", \"Extra element\"],\n-          [\"-\", \"[4]\", \"Missing element\"],\n-          [\"~\", \"[5]\", \"Changed element\"],\n-          [\"-\", \"[3]\", {moved_complex_object: 1}],\n-          [\"+\", \"[6]\", {moved_complex_object: 1}],\n-        ])\n-      ]\n-    }\n-\n-    let(:redis) { double(:redis) }\n+    let(:experiment_result) do\n+      JSON.dump([\n+        [\"-\", \"[1]\", { same_key: 1, different_key: 2 }],\n+        [\"+\", \"[2]\", { same_key: 1, different_key: 3 }],\n+        [\"+\", \"[3]\", \"Extra element\"],\n+        [\"-\", \"[4]\", \"Missing element\"],\n+        [\"~\", \"[5]\", \"Changed element\"],\n+        [\"-\", \"[3]\", { moved_complex_object: 1 }],\n+        [\"+\", \"[6]\", { moved_complex_object: 1 }],\n+      ])\n+    end\n \n     before do\n-      allow(Sidekiq).to receive(:redis).and_yield(redis)\n-      allow(redis).to receive(:lrange).with(\"experiments:#{name}:mismatches\", 0, -1)\n-        .and_return(experiment_results)\n+      allow(redis).to receive(:scan_each).and_return([1])\n+      allow(redis).to receive(:get).and_return(experiment_result)\n     end\n \n     it \"partitions and resorts experiment results for useful output\" do\n       results = described_class.get_experiment_data(name)\n \n       expect(results).to eq([\n         missing: [\n-          {\"same_key\" => 1, \"different_key\" => 2},\n+          { \"same_key\" => 1, \"different_key\" => 2 },","path":"spec/async_experiments_spec.rb","position":60,"original_position":60,"commit_id":"22f40bebac25cbbf4612847b75644b49ef42b9f4","original_commit_id":"22f40bebac25cbbf4612847b75644b49ef42b9f4","user":{"login":"carlosmartinez","id":168365,"avatar_url":"https://avatars.githubusercontent.com/u/168365?v=3","gravatar_id":"","url":"https://api.github.com/users/carlosmartinez","html_url":"https://github.com/carlosmartinez","followers_url":"https://api.github.com/users/carlosmartinez/followers","following_url":"https://api.github.com/users/carlosmartinez/following{/other_user}","gists_url":"https://api.github.com/users/carlosmartinez/gists{/gist_id}","starred_url":"https://api.github.com/users/carlosmartinez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carlosmartinez/subscriptions","organizations_url":"https://api.github.com/users/carlosmartinez/orgs","repos_url":"https://api.github.com/users/carlosmartinez/repos","events_url":"https://api.github.com/users/carlosmartinez/events{/privacy}","received_events_url":"https://api.github.com/users/carlosmartinez/received_events","type":"User","site_admin":false},"body":"the formatting gods are smiling on you","created_at":"2016-09-09T09:46:25Z","updated_at":"2016-09-09T09:46:25Z","html_url":"https://github.com/alphagov/async_experiments/pull/1#discussion_r78154688","pull_request_url":"https://api.github.com/repos/alphagov/async_experiments/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/alphagov/async_experiments/pulls/comments/78154688"},"html":{"href":"https://github.com/alphagov/async_experiments/pull/1#discussion_r78154688"},"pull_request":{"href":"https://api.github.com/repos/alphagov/async_experiments/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/async_experiments/pulls/1","id":84295645,"html_url":"https://github.com/alphagov/async_experiments/pull/1","diff_url":"https://github.com/alphagov/async_experiments/pull/1.diff","patch_url":"https://github.com/alphagov/async_experiments/pull/1.patch","issue_url":"https://api.github.com/repos/alphagov/async_experiments/issues/1","number":1,"state":"open","locked":false,"title":"Friendlier use of Redis ","user":{"login":"kevindew","id":282717,"avatar_url":"https://avatars.githubusercontent.com/u/282717?v=3","gravatar_id":"","url":"https://api.github.com/users/kevindew","html_url":"https://github.com/kevindew","followers_url":"https://api.github.com/users/kevindew/followers","following_url":"https://api.github.com/users/kevindew/following{/other_user}","gists_url":"https://api.github.com/users/kevindew/gists{/gist_id}","starred_url":"https://api.github.com/users/kevindew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevindew/subscriptions","organizations_url":"https://api.github.com/users/kevindew/orgs","repos_url":"https://api.github.com/users/kevindew/repos","events_url":"https://api.github.com/users/kevindew/events{/privacy}","received_events_url":"https://api.github.com/users/kevindew/received_events","type":"User","site_admin":false},"body":"Based off this card: https://trello.com/c/o0i6SGFf/794-experiments-framework-fix-medium and a chat with @steventux \r\n\r\nThis PR covers 3 aspects and can be broken down if any of these require extra discussion.\r\n\r\n### Set expiry dates on all data going into redis\r\n\r\nEach time we set data in redis we set an expiry on it to allow redis to auto clean-up that data.\r\nBy default this is set to 60 seconds for candidate data and 24 hours for a result. This can be configured with arguments to the `experiment_control` method:\r\n\r\n```ruby\r\nexperiment_control(..., results_expiry: 60 * 5, candidate_expiry: 60)\r\n```\r\n\r\nWe also only retry 5 times in the control worker to see if candidate data is ready otherwise we abort.\r\n\r\n### Update documentation\r\n\r\nI've added some more information on what this thing is, what it does and how to set it up - with a link to a working example in publishing-api\r\n\r\n### Less duplicate data in redis\r\n\r\nIn the cases where we're storing mismatches and errors I've switched it to store a sha2 hash of the data as part of the key and not add new entries into redis when we already have one item matching that hash. This is to reduce the amount of data that is redundantly stored in redis.\r\n\r\n@elliotcm as original author I thought best to tag you in so you get a notification.\r\n","created_at":"2016-09-07T13:01:15Z","updated_at":"2016-09-09T09:46:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"17333a0d7e312f2262fddea37ea6dc47eda4ca8d","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/async_experiments/pulls/1/commits","review_comments_url":"https://api.github.com/repos/alphagov/async_experiments/pulls/1/comments","review_comment_url":"https://api.github.com/repos/alphagov/async_experiments/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alphagov/async_experiments/issues/1/comments","statuses_url":"https://api.github.com/repos/alphagov/async_experiments/statuses/22f40bebac25cbbf4612847b75644b49ef42b9f4","head":{"label":"alphagov:friendlier-data","ref":"friendlier-data","sha":"22f40bebac25cbbf4612847b75644b49ef42b9f4","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":61360521,"name":"async_experiments","full_name":"alphagov/async_experiments","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/async_experiments","description":"","fork":false,"url":"https://api.github.com/repos/alphagov/async_experiments","forks_url":"https://api.github.com/repos/alphagov/async_experiments/forks","keys_url":"https://api.github.com/repos/alphagov/async_experiments/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/async_experiments/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/async_experiments/teams","hooks_url":"https://api.github.com/repos/alphagov/async_experiments/hooks","issue_events_url":"https://api.github.com/repos/alphagov/async_experiments/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/async_experiments/events","assignees_url":"https://api.github.com/repos/alphagov/async_experiments/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/async_experiments/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/async_experiments/tags","blobs_url":"https://api.github.com/repos/alphagov/async_experiments/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/async_experiments/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/async_experiments/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/async_experiments/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/async_experiments/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/async_experiments/languages","stargazers_url":"https://api.github.com/repos/alphagov/async_experiments/stargazers","contributors_url":"https://api.github.com/repos/alphagov/async_experiments/contributors","subscribers_url":"https://api.github.com/repos/alphagov/async_experiments/subscribers","subscription_url":"https://api.github.com/repos/alphagov/async_experiments/subscription","commits_url":"https://api.github.com/repos/alphagov/async_experiments/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/async_experiments/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/async_experiments/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/async_experiments/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/async_experiments/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/async_experiments/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/async_experiments/merges","archive_url":"https://api.github.com/repos/alphagov/async_experiments/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/async_experiments/downloads","issues_url":"https://api.github.com/repos/alphagov/async_experiments/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/async_experiments/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/async_experiments/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/async_experiments/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/async_experiments/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/async_experiments/releases{/id}","deployments_url":"https://api.github.com/repos/alphagov/async_experiments/deployments","created_at":"2016-06-17T09:02:28Z","updated_at":"2016-06-17T15:49:17Z","pushed_at":"2016-09-07T13:01:16Z","git_url":"git://github.com/alphagov/async_experiments.git","ssh_url":"git@github.com:alphagov/async_experiments.git","clone_url":"https://github.com/alphagov/async_experiments.git","svn_url":"https://github.com/alphagov/async_experiments","homepage":null,"size":32,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"9c9de959e84f4350a3e070758431a2e8d6eb9496","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":61360521,"name":"async_experiments","full_name":"alphagov/async_experiments","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/async_experiments","description":"","fork":false,"url":"https://api.github.com/repos/alphagov/async_experiments","forks_url":"https://api.github.com/repos/alphagov/async_experiments/forks","keys_url":"https://api.github.com/repos/alphagov/async_experiments/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/async_experiments/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/async_experiments/teams","hooks_url":"https://api.github.com/repos/alphagov/async_experiments/hooks","issue_events_url":"https://api.github.com/repos/alphagov/async_experiments/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/async_experiments/events","assignees_url":"https://api.github.com/repos/alphagov/async_experiments/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/async_experiments/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/async_experiments/tags","blobs_url":"https://api.github.com/repos/alphagov/async_experiments/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/async_experiments/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/async_experiments/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/async_experiments/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/async_experiments/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/async_experiments/languages","stargazers_url":"https://api.github.com/repos/alphagov/async_experiments/stargazers","contributors_url":"https://api.github.com/repos/alphagov/async_experiments/contributors","subscribers_url":"https://api.github.com/repos/alphagov/async_experiments/subscribers","subscription_url":"https://api.github.com/repos/alphagov/async_experiments/subscription","commits_url":"https://api.github.com/repos/alphagov/async_experiments/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/async_experiments/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/async_experiments/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/async_experiments/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/async_experiments/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/async_experiments/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/async_experiments/merges","archive_url":"https://api.github.com/repos/alphagov/async_experiments/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/async_experiments/downloads","issues_url":"https://api.github.com/repos/alphagov/async_experiments/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/async_experiments/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/async_experiments/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/async_experiments/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/async_experiments/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/async_experiments/releases{/id}","deployments_url":"https://api.github.com/repos/alphagov/async_experiments/deployments","created_at":"2016-06-17T09:02:28Z","updated_at":"2016-06-17T15:49:17Z","pushed_at":"2016-09-07T13:01:16Z","git_url":"git://github.com/alphagov/async_experiments.git","ssh_url":"git@github.com:alphagov/async_experiments.git","clone_url":"https://github.com/alphagov/async_experiments.git","svn_url":"https://github.com/alphagov/async_experiments","homepage":null,"size":32,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/async_experiments/pulls/1"},"html":{"href":"https://github.com/alphagov/async_experiments/pull/1"},"issue":{"href":"https://api.github.com/repos/alphagov/async_experiments/issues/1"},"comments":{"href":"https://api.github.com/repos/alphagov/async_experiments/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/async_experiments/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/async_experiments/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alphagov/async_experiments/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/async_experiments/statuses/22f40bebac25cbbf4612847b75644b49ef42b9f4"}}}}
{"actor":{"display_login":"carlosmartinez"}}