{"action":"created","comment":{"url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/pulls/comments/85121679","pull_request_review_id":5854776,"id":85121679,"diff_hunk":"@@ -0,0 +1,146 @@\n+---\n+layout: post\n+title: Unit test tips & tricks - Episode 1 - Avoid timeout in async test\n+tip-number: 08\n+tip-username: Sang D. Ngo\n+tip-username-profile: https://github.com/heroandtn3\n+tip-tldr: How to avoid timeout error in async test cases\n+---\n+\n+We write unit test everywhere in OpenPaas, some of them are async, let's see an example:\n+\n+```javascript\n+getModule()\n+  .findByDomainId()\n+  .then(function(configuration) {\n+    expect(configuration.modules).to.have.length(2);\n+    done();\n+  });\n+```\n+\n+It won't be a problem if it passes, but what if it fails?\n+\n+```\n+Error: timeout of 20000ms exceeded. Ensure the done() callback is being called in this test.\n+```\n+\n+Well, the test case got hang for 20s then printed out an error message that isn'\n+helpful at all. Why the `done()` was not called? Did the promise reject? Did\n+the promise take too much time to resolve? You start debuging the failed test by\n+commenting the `expect` statement:\n+\n+```javascript\n+getModule()\n+  .findByDomainId()\n+  .then(function(configuration) {\n+    //expect(configuration.modules).to.have.length(2);\n+    done();\n+  });\n+```\n+\n+And it passed!\n+\n+```\n+Done, without errors.\n+```\n+\n+Obviously, the problem comes from the `expect` statement, you continue with:\n+\n+```javascript\n+getModule()\n+  .findByDomainId()\n+  .then(function(configuration) {\n+    console.log('Length:', configuration.modules.length);\n+    //expect(configuration.modules).to.have.length(2);\n+    done();\n+  });\n+```\n+\n+```\n+Length: 1\n+```\n+\n+Cool! Finally, you found the source of the problem. You fix your code or your mock,\n+the test comes green, you feel so happy.\n+\n+Well, it would not be easy like that when your test fails on Jenkins,\n+especially with random failure. You may already knew, sometimes we have random failure\n+on Jenkins and the error message is just `Error: timeout of 20000ms exceeded`,","path":"_posts/2016-10-21-unit-test-e1-async-test.md","position":68,"original_position":68,"commit_id":"6ea1f4bcd5373ad05bd0d0028fbf04821497f087","original_commit_id":"6ea1f4bcd5373ad05bd0d0028fbf04821497f087","user":{"login":"heroandtn3","id":2512088,"avatar_url":"https://avatars.githubusercontent.com/u/2512088?v=3","gravatar_id":"","url":"https://api.github.com/users/heroandtn3","html_url":"https://github.com/heroandtn3","followers_url":"https://api.github.com/users/heroandtn3/followers","following_url":"https://api.github.com/users/heroandtn3/following{/other_user}","gists_url":"https://api.github.com/users/heroandtn3/gists{/gist_id}","starred_url":"https://api.github.com/users/heroandtn3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroandtn3/subscriptions","organizations_url":"https://api.github.com/users/heroandtn3/orgs","repos_url":"https://api.github.com/users/heroandtn3/repos","events_url":"https://api.github.com/users/heroandtn3/events{/privacy}","received_events_url":"https://api.github.com/users/heroandtn3/received_events","type":"User","site_admin":false},"body":"Splitted to two sentences, removed Jenkins word","created_at":"2016-10-26T13:30:19Z","updated_at":"2016-10-26T13:30:19Z","html_url":"https://github.com/linagora/openpaas-tip-of-the-day/pull/23#discussion_r85121679","pull_request_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/pulls/23","_links":{"self":{"href":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/pulls/comments/85121679"},"html":{"href":"https://github.com/linagora/openpaas-tip-of-the-day/pull/23#discussion_r85121679"},"pull_request":{"href":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/pulls/23"}}},"pull_request":{"url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/pulls/23","id":90409564,"html_url":"https://github.com/linagora/openpaas-tip-of-the-day/pull/23","diff_url":"https://github.com/linagora/openpaas-tip-of-the-day/pull/23.diff","patch_url":"https://github.com/linagora/openpaas-tip-of-the-day/pull/23.patch","issue_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/issues/23","number":23,"state":"open","locked":false,"title":"Add: Unit test tips & tricks - Episode 1 - Avoid timeout in async test","user":{"login":"heroandtn3","id":2512088,"avatar_url":"https://avatars.githubusercontent.com/u/2512088?v=3","gravatar_id":"","url":"https://api.github.com/users/heroandtn3","html_url":"https://github.com/heroandtn3","followers_url":"https://api.github.com/users/heroandtn3/followers","following_url":"https://api.github.com/users/heroandtn3/following{/other_user}","gists_url":"https://api.github.com/users/heroandtn3/gists{/gist_id}","starred_url":"https://api.github.com/users/heroandtn3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroandtn3/subscriptions","organizations_url":"https://api.github.com/users/heroandtn3/orgs","repos_url":"https://api.github.com/users/heroandtn3/repos","events_url":"https://api.github.com/users/heroandtn3/events{/privacy}","received_events_url":"https://api.github.com/users/heroandtn3/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-10-21T15:58:49Z","updated_at":"2016-10-26T13:30:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b5cc3a9e289d08ee0dec9bb3712739b6df57aa85","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/pulls/23/commits","review_comments_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/pulls/23/comments","review_comment_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/pulls/comments{/number}","comments_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/issues/23/comments","statuses_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/statuses/6ea1f4bcd5373ad05bd0d0028fbf04821497f087","head":{"label":"heroandtn3:gh-pages","ref":"gh-pages","sha":"6ea1f4bcd5373ad05bd0d0028fbf04821497f087","user":{"login":"heroandtn3","id":2512088,"avatar_url":"https://avatars.githubusercontent.com/u/2512088?v=3","gravatar_id":"","url":"https://api.github.com/users/heroandtn3","html_url":"https://github.com/heroandtn3","followers_url":"https://api.github.com/users/heroandtn3/followers","following_url":"https://api.github.com/users/heroandtn3/following{/other_user}","gists_url":"https://api.github.com/users/heroandtn3/gists{/gist_id}","starred_url":"https://api.github.com/users/heroandtn3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroandtn3/subscriptions","organizations_url":"https://api.github.com/users/heroandtn3/orgs","repos_url":"https://api.github.com/users/heroandtn3/repos","events_url":"https://api.github.com/users/heroandtn3/events{/privacy}","received_events_url":"https://api.github.com/users/heroandtn3/received_events","type":"User","site_admin":false},"repo":{"id":55985744,"name":"openpaas-tip-of-the-day","full_name":"heroandtn3/openpaas-tip-of-the-day","owner":{"login":"heroandtn3","id":2512088,"avatar_url":"https://avatars.githubusercontent.com/u/2512088?v=3","gravatar_id":"","url":"https://api.github.com/users/heroandtn3","html_url":"https://github.com/heroandtn3","followers_url":"https://api.github.com/users/heroandtn3/followers","following_url":"https://api.github.com/users/heroandtn3/following{/other_user}","gists_url":"https://api.github.com/users/heroandtn3/gists{/gist_id}","starred_url":"https://api.github.com/users/heroandtn3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroandtn3/subscriptions","organizations_url":"https://api.github.com/users/heroandtn3/orgs","repos_url":"https://api.github.com/users/heroandtn3/repos","events_url":"https://api.github.com/users/heroandtn3/events{/privacy}","received_events_url":"https://api.github.com/users/heroandtn3/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/heroandtn3/openpaas-tip-of-the-day","description":"Contributing and coding in OpenPaas demystified through one tip per day.","fork":true,"url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day","forks_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/forks","keys_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/keys{/key_id}","collaborators_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/teams","hooks_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/hooks","issue_events_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/issues/events{/number}","events_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/events","assignees_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/assignees{/user}","branches_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/branches{/branch}","tags_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/tags","blobs_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/git/refs{/sha}","trees_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/git/trees{/sha}","statuses_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/statuses/{sha}","languages_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/languages","stargazers_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/stargazers","contributors_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/contributors","subscribers_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/subscribers","subscription_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/subscription","commits_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/commits{/sha}","git_commits_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/git/commits{/sha}","comments_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/comments{/number}","issue_comment_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/issues/comments{/number}","contents_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/contents/{+path}","compare_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/compare/{base}...{head}","merges_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/merges","archive_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/downloads","issues_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/issues{/number}","pulls_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/pulls{/number}","milestones_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/milestones{/number}","notifications_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/labels{/name}","releases_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/releases{/id}","deployments_url":"https://api.github.com/repos/heroandtn3/openpaas-tip-of-the-day/deployments","created_at":"2016-04-11T15:45:13Z","updated_at":"2016-04-11T15:45:14Z","pushed_at":"2016-10-21T15:57:09Z","git_url":"git://github.com/heroandtn3/openpaas-tip-of-the-day.git","ssh_url":"git@github.com:heroandtn3/openpaas-tip-of-the-day.git","clone_url":"https://github.com/heroandtn3/openpaas-tip-of-the-day.git","svn_url":"https://github.com/heroandtn3/openpaas-tip-of-the-day","homepage":"http://linagora.github.io/openpaas-tip-of-the-day/","size":1505,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"gh-pages"}},"base":{"label":"linagora:gh-pages","ref":"gh-pages","sha":"91668197f8377af53e4a1d2c50c4366c8f6d3420","user":{"login":"linagora","id":1230365,"avatar_url":"https://avatars.githubusercontent.com/u/1230365?v=3","gravatar_id":"","url":"https://api.github.com/users/linagora","html_url":"https://github.com/linagora","followers_url":"https://api.github.com/users/linagora/followers","following_url":"https://api.github.com/users/linagora/following{/other_user}","gists_url":"https://api.github.com/users/linagora/gists{/gist_id}","starred_url":"https://api.github.com/users/linagora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/linagora/subscriptions","organizations_url":"https://api.github.com/users/linagora/orgs","repos_url":"https://api.github.com/users/linagora/repos","events_url":"https://api.github.com/users/linagora/events{/privacy}","received_events_url":"https://api.github.com/users/linagora/received_events","type":"Organization","site_admin":false},"repo":{"id":50936281,"name":"openpaas-tip-of-the-day","full_name":"linagora/openpaas-tip-of-the-day","owner":{"login":"linagora","id":1230365,"avatar_url":"https://avatars.githubusercontent.com/u/1230365?v=3","gravatar_id":"","url":"https://api.github.com/users/linagora","html_url":"https://github.com/linagora","followers_url":"https://api.github.com/users/linagora/followers","following_url":"https://api.github.com/users/linagora/following{/other_user}","gists_url":"https://api.github.com/users/linagora/gists{/gist_id}","starred_url":"https://api.github.com/users/linagora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/linagora/subscriptions","organizations_url":"https://api.github.com/users/linagora/orgs","repos_url":"https://api.github.com/users/linagora/repos","events_url":"https://api.github.com/users/linagora/events{/privacy}","received_events_url":"https://api.github.com/users/linagora/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/linagora/openpaas-tip-of-the-day","description":"Contributing and coding in OpenPaas demystified through one tip per day.","fork":false,"url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day","forks_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/forks","keys_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/keys{/key_id}","collaborators_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/teams","hooks_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/hooks","issue_events_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/issues/events{/number}","events_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/events","assignees_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/assignees{/user}","branches_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/branches{/branch}","tags_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/tags","blobs_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/git/refs{/sha}","trees_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/git/trees{/sha}","statuses_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/statuses/{sha}","languages_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/languages","stargazers_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/stargazers","contributors_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/contributors","subscribers_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/subscribers","subscription_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/subscription","commits_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/commits{/sha}","git_commits_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/git/commits{/sha}","comments_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/comments{/number}","issue_comment_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/issues/comments{/number}","contents_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/contents/{+path}","compare_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/compare/{base}...{head}","merges_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/merges","archive_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/downloads","issues_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/issues{/number}","pulls_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/pulls{/number}","milestones_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/milestones{/number}","notifications_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/labels{/name}","releases_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/releases{/id}","deployments_url":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/deployments","created_at":"2016-02-02T16:56:38Z","updated_at":"2016-05-29T05:25:47Z","pushed_at":"2016-10-21T15:58:49Z","git_url":"git://github.com/linagora/openpaas-tip-of-the-day.git","ssh_url":"git@github.com:linagora/openpaas-tip-of-the-day.git","clone_url":"https://github.com/linagora/openpaas-tip-of-the-day.git","svn_url":"https://github.com/linagora/openpaas-tip-of-the-day","homepage":"http://linagora.github.io/openpaas-tip-of-the-day/","size":1504,"stargazers_count":11,"watchers_count":11,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":8,"mirror_url":null,"open_issues_count":5,"forks":8,"open_issues":5,"watchers":11,"default_branch":"gh-pages"}},"_links":{"self":{"href":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/pulls/23"},"html":{"href":"https://github.com/linagora/openpaas-tip-of-the-day/pull/23"},"issue":{"href":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/issues/23"},"comments":{"href":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/pulls/23/comments"},"review_comment":{"href":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/pulls/23/commits"},"statuses":{"href":"https://api.github.com/repos/linagora/openpaas-tip-of-the-day/statuses/6ea1f4bcd5373ad05bd0d0028fbf04821497f087"}}}}
{"actor":{"display_login":"heroandtn3"}}