GitHub PullRequestReviewCommentEvent at 2014-06-12 20:51:50
Repository: lasse
Actor: elbrujohalcon
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/inaka/lasse/pulls/comments/13725556","id":13725556,"diff_hunk":"@@ -0,0 +1,135 @@\n+%%% @doc Test suite for the Cowboy's Server-Sent Events handler.\n+-module(lasse_handler_SUITE).\n+\n+-type config() :: [{atom(), term()}].\n+\n+-export([all/0]).\n+\n+-export([\n+         init_per_suite/1,\n+         end_per_suite/1\n+        ]).\n+\n+-export([\n+         send_and_receive_two_chunks/1,\n+         shutdown_check_response/1,\n+         init_without_module_option/1,\n+         init_with_module_option/1\n+        ]).\n+\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%%% Common test functions\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+\n+%% @private\n+-spec all() -> [atom()].\n+all() ->\n+    [\n+     send_and_receive_two_chunks,\n+     shutdown_check_response,\n+     init_without_module_option,\n+     init_with_module_option\n+    ].\n+\n+-spec init_per_suite(config()) -> config().\n+init_per_suite(Config) ->\n+    {ok, _Started} = application:ensure_all_started(lasse_server),\n+\n+    Config.\n+\n+-spec end_per_suite(config()) -> config().\n+end_per_suite(Config) ->\n+    application:stop(lasse_server),\n+\n+    Config.\n+\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%%% Tests Cases\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+\n+-spec send_and_receive_two_chunks(config()) -> ok.\n+send_and_receive_two_chunks(_Config) ->\n+    %  Client connection is opened here\n+    % since doing it in init_per_suite and\n+    % providing the resulting Pid doesn't work.'\n+    Pid = open_conn(),\n+    ok = lasse_client:get(Pid, \"/events\"),\n+    Fun = fun() -> whereis(events_handler) =/= undefined end,\n+    wait_for(Fun, 100),\n+    % first chunk\n+    lasse_handler:notify(events_handler, <<\"notify chunk\">>),\n+    {chunk, <<\"data: notify chunk\\n\\n\">>} = response(),\n+    % second chunk\n+    events_handler ! <<\"info chunk\">>,\n+    {chunk, <<\"data: info chunk\\n\\n\">>} = response(),\n+\n+    lasse_client:close(Pid).\n+\n+-spec shutdown_check_response(config()) -> ok.\n+shutdown_check_response(_Config) ->\n+    Pid = open_conn(),\n+    ok = lasse_client:get(Pid, \"/shutdown\"),\n+    <<\"Sorry, shutdown!\">> = response(),\n+\n+    lasse_client:close(Pid).\n+\n+-spec init_without_module_option(config()) -> ok.\n+init_without_module_option(_Config) ->\n+    try\n+        Opts = [],\n+        lasse_handler:init({}, {}, Opts)\n+    catch\n+        throw:_ -> ok\n+    end,\n+    try\n+        Opts2 = [{init_args, []}],\n+        lasse_handler:init({}, {}, Opts2)\n+    catch\n+        throw:module_option_missing ->\n+            % lager:info(\"~p\", [Error]),\n+            ok\n+    end.\n+\n+-spec init_with_module_option(config()) -> ok.\n+init_with_module_option(_Config) ->\n+    try\n+        Opts = [{module, dummy_handler}],\n+        lasse_handler:init({}, {}, Opts)\n+    catch\n+        error:function_clause -> ok\n+    end.\n+\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+%%% Auxiliary functions\n+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n+\n+%% @doc Waits for messages that are supposed to be a reponse\n+-spec response() -> binary() | {chunk, binary()}.\n+response() ->\n+    receive\n+        {response, Data} -> Data;\n+        {chunk, Chunk} -> {chunk, Chunk}\n+    after 5000 ->\n+            exit(no_event_from_server)\n+    end.\n+\n+-spec open_conn() -> pid().\n+open_conn() ->\n+    {ok, Port} = application:get_env(cowboy, http_port),\n+    Host = \"localhost\",\n+    lasse_client:open(Host, Port).\n+\n+wait_for(Fun, Timeout) ->\n+    SleepTime = 10,\n+    Retries = erlang:round(Timeout / SleepTime),","path":"test/lasse_handler_SUITE.erl","position":124,"original_position":124,"commit_id":"29c9262f50a8a216c5a961037c27546d7f2b25ad","original_commit_id":"29c9262f50a8a216c5a961037c27546d7f2b25ad","user":{"login":"elbrujohalcon","id":93657,"avatar_url":"https://avatars.githubusercontent.com/u/93657?","gravatar_id":"a276ac864be6c4aa409879272e613172","url":"https://api.github.com/users/elbrujohalcon","html_url":"https://github.com/elbrujohalcon","followers_url":"https://api.github.com/users/elbrujohalcon/followers","following_url":"https://api.github.com/users/elbrujohalcon/following{/other_user}","gists_url":"https://api.github.com/users/elbrujohalcon/gists{/gist_id}","starred_url":"https://api.github.com/users/elbrujohalcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elbrujohalcon/subscriptions","organizations_url":"https://api.github.com/users/elbrujohalcon/orgs","repos_url":"https://api.github.com/users/elbrujohalcon/repos","events_url":"https://api.github.com/users/elbrujohalcon/events{/privacy}","received_events_url":"https://api.github.com/users/elbrujohalcon/received_events","type":"User","site_admin":false},"body":"you can use ``Timeout div SleepTime``, I think","created_at":"2014-06-12T20:51:50Z","updated_at":"2014-06-12T20:51:50Z","html_url":"https://github.com/inaka/lasse/pull/8#discussion_r13725556","pull_request_url":"https://api.github.com/repos/inaka/lasse/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/inaka/lasse/pulls/comments/13725556"},"html":{"href":"https://github.com/inaka/lasse/pull/8#discussion_r13725556"},"pull_request":{"href":"https://api.github.com/repos/inaka/lasse/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/inaka/lasse/pulls/8","id":17078186,"html_url":"https://github.com/inaka/lasse/pull/8","diff_url":"https://github.com/inaka/lasse/pull/8.diff","patch_url":"https://github.com/inaka/lasse/pull/8.patch","issue_url":"https://api.github.com/repos/inaka/lasse/issues/8","number":8,"state":"open","title":"[#3] Created test suite for lasse.","user":{"login":"jfacorro","id":1522569,"avatar_url":"https://avatars.githubusercontent.com/u/1522569?","gravatar_id":"d6f59d93cc17c698f16e550034a2d1ad","url":"https://api.github.com/users/jfacorro","html_url":"https://github.com/jfacorro","followers_url":"https://api.github.com/users/jfacorro/followers","following_url":"https://api.github.com/users/jfacorro/following{/other_user}","gists_url":"https://api.github.com/users/jfacorro/gists{/gist_id}","starred_url":"https://api.github.com/users/jfacorro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfacorro/subscriptions","organizations_url":"https://api.github.com/users/jfacorro/orgs","repos_url":"https://api.github.com/users/jfacorro/repos","events_url":"https://api.github.com/users/jfacorro/events{/privacy}","received_events_url":"https://api.github.com/users/jfacorro/received_events","type":"User","site_admin":false},"body":"... using [gun](https://github.com/extend/gun) for the HTTP client and cowboy for the server.","created_at":"2014-06-12T20:35:21Z","updated_at":"2014-06-12T20:51:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0aae16bbc9f92ff043fcf935f1c0e3cd24384c3e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/inaka/lasse/pulls/8/commits","review_comments_url":"https://api.github.com/repos/inaka/lasse/pulls/8/comments","review_comment_url":"https://api.github.com/repos/inaka/lasse/pulls/comments/{number}","comments_url":"https://api.github.com/repos/inaka/lasse/issues/8/comments","statuses_url":"https://api.github.com/repos/inaka/lasse/statuses/29c9262f50a8a216c5a961037c27546d7f2b25ad","head":{"label":"inaka:jfacorro.3.tests","ref":"jfacorro.3.tests","sha":"29c9262f50a8a216c5a961037c27546d7f2b25ad","user":{"login":"inaka","id":867053,"avatar_url":"https://avatars.githubusercontent.com/u/867053?","gravatar_id":"1965362c650bbdd4cbaadf0f1ac45f7e","url":"https://api.github.com/users/inaka","html_url":"https://github.com/inaka","followers_url":"https://api.github.com/users/inaka/followers","following_url":"https://api.github.com/users/inaka/following{/other_user}","gists_url":"https://api.github.com/users/inaka/gists{/gist_id}","starred_url":"https://api.github.com/users/inaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inaka/subscriptions","organizations_url":"https://api.github.com/users/inaka/orgs","repos_url":"https://api.github.com/users/inaka/repos","events_url":"https://api.github.com/users/inaka/events{/privacy}","received_events_url":"https://api.github.com/users/inaka/received_events","type":"Organization","site_admin":false},"repo":{"id":20452255,"name":"lasse","full_name":"inaka/lasse","owner":{"login":"inaka","id":867053,"avatar_url":"https://avatars.githubusercontent.com/u/867053?","gravatar_id":"1965362c650bbdd4cbaadf0f1ac45f7e","url":"https://api.github.com/users/inaka","html_url":"https://github.com/inaka","followers_url":"https://api.github.com/users/inaka/followers","following_url":"https://api.github.com/users/inaka/following{/other_user}","gists_url":"https://api.github.com/users/inaka/gists{/gist_id}","starred_url":"https://api.github.com/users/inaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inaka/subscriptions","organizations_url":"https://api.github.com/users/inaka/orgs","repos_url":"https://api.github.com/users/inaka/repos","events_url":"https://api.github.com/users/inaka/events{/privacy}","received_events_url":"https://api.github.com/users/inaka/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/inaka/lasse","description":"SSE handler for Cowboy","fork":false,"url":"https://api.github.com/repos/inaka/lasse","forks_url":"https://api.github.com/repos/inaka/lasse/forks","keys_url":"https://api.github.com/repos/inaka/lasse/keys{/key_id}","collaborators_url":"https://api.github.com/repos/inaka/lasse/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/inaka/lasse/teams","hooks_url":"https://api.github.com/repos/inaka/lasse/hooks","issue_events_url":"https://api.github.com/repos/inaka/lasse/issues/events{/number}","events_url":"https://api.github.com/repos/inaka/lasse/events","assignees_url":"https://api.github.com/repos/inaka/lasse/assignees{/user}","branches_url":"https://api.github.com/repos/inaka/lasse/branches{/branch}","tags_url":"https://api.github.com/repos/inaka/lasse/tags","blobs_url":"https://api.github.com/repos/inaka/lasse/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/inaka/lasse/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/inaka/lasse/git/refs{/sha}","trees_url":"https://api.github.com/repos/inaka/lasse/git/trees{/sha}","statuses_url":"https://api.github.com/repos/inaka/lasse/statuses/{sha}","languages_url":"https://api.github.com/repos/inaka/lasse/languages","stargazers_url":"https://api.github.com/repos/inaka/lasse/stargazers","contributors_url":"https://api.github.com/repos/inaka/lasse/contributors","subscribers_url":"https://api.github.com/repos/inaka/lasse/subscribers","subscription_url":"https://api.github.com/repos/inaka/lasse/subscription","commits_url":"https://api.github.com/repos/inaka/lasse/commits{/sha}","git_commits_url":"https://api.github.com/repos/inaka/lasse/git/commits{/sha}","comments_url":"https://api.github.com/repos/inaka/lasse/comments{/number}","issue_comment_url":"https://api.github.com/repos/inaka/lasse/issues/comments/{number}","contents_url":"https://api.github.com/repos/inaka/lasse/contents/{+path}","compare_url":"https://api.github.com/repos/inaka/lasse/compare/{base}...{head}","merges_url":"https://api.github.com/repos/inaka/lasse/merges","archive_url":"https://api.github.com/repos/inaka/lasse/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/inaka/lasse/downloads","issues_url":"https://api.github.com/repos/inaka/lasse/issues{/number}","pulls_url":"https://api.github.com/repos/inaka/lasse/pulls{/number}","milestones_url":"https://api.github.com/repos/inaka/lasse/milestones{/number}","notifications_url":"https://api.github.com/repos/inaka/lasse/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/inaka/lasse/labels{/name}","releases_url":"https://api.github.com/repos/inaka/lasse/releases{/id}","created_at":"2014-06-03T17:24:57Z","updated_at":"2014-06-12T20:35:21Z","pushed_at":"2014-06-12T20:32:30Z","git_url":"git://github.com/inaka/lasse.git","ssh_url":"git@github.com:inaka/lasse.git","clone_url":"https://github.com/inaka/lasse.git","svn_url":"https://github.com/inaka/lasse","homepage":null,"size":256,"stargazers_count":0,"watchers_count":0,"language":"Erlang","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"inaka:master","ref":"master","sha":"b7ce79ddc0514b3c95d10f84b60e0bd2765eccab","user":{"login":"inaka","id":867053,"avatar_url":"https://avatars.githubusercontent.com/u/867053?","gravatar_id":"1965362c650bbdd4cbaadf0f1ac45f7e","url":"https://api.github.com/users/inaka","html_url":"https://github.com/inaka","followers_url":"https://api.github.com/users/inaka/followers","following_url":"https://api.github.com/users/inaka/following{/other_user}","gists_url":"https://api.github.com/users/inaka/gists{/gist_id}","starred_url":"https://api.github.com/users/inaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inaka/subscriptions","organizations_url":"https://api.github.com/users/inaka/orgs","repos_url":"https://api.github.com/users/inaka/repos","events_url":"https://api.github.com/users/inaka/events{/privacy}","received_events_url":"https://api.github.com/users/inaka/received_events","type":"Organization","site_admin":false},"repo":{"id":20452255,"name":"lasse","full_name":"inaka/lasse","owner":{"login":"inaka","id":867053,"avatar_url":"https://avatars.githubusercontent.com/u/867053?","gravatar_id":"1965362c650bbdd4cbaadf0f1ac45f7e","url":"https://api.github.com/users/inaka","html_url":"https://github.com/inaka","followers_url":"https://api.github.com/users/inaka/followers","following_url":"https://api.github.com/users/inaka/following{/other_user}","gists_url":"https://api.github.com/users/inaka/gists{/gist_id}","starred_url":"https://api.github.com/users/inaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inaka/subscriptions","organizations_url":"https://api.github.com/users/inaka/orgs","repos_url":"https://api.github.com/users/inaka/repos","events_url":"https://api.github.com/users/inaka/events{/privacy}","received_events_url":"https://api.github.com/users/inaka/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/inaka/lasse","description":"SSE handler for Cowboy","fork":false,"url":"https://api.github.com/repos/inaka/lasse","forks_url":"https://api.github.com/repos/inaka/lasse/forks","keys_url":"https://api.github.com/repos/inaka/lasse/keys{/key_id}","collaborators_url":"https://api.github.com/repos/inaka/lasse/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/inaka/lasse/teams","hooks_url":"https://api.github.com/repos/inaka/lasse/hooks","issue_events_url":"https://api.github.com/repos/inaka/lasse/issues/events{/number}","events_url":"https://api.github.com/repos/inaka/lasse/events","assignees_url":"https://api.github.com/repos/inaka/lasse/assignees{/user}","branches_url":"https://api.github.com/repos/inaka/lasse/branches{/branch}","tags_url":"https://api.github.com/repos/inaka/lasse/tags","blobs_url":"https://api.github.com/repos/inaka/lasse/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/inaka/lasse/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/inaka/lasse/git/refs{/sha}","trees_url":"https://api.github.com/repos/inaka/lasse/git/trees{/sha}","statuses_url":"https://api.github.com/repos/inaka/lasse/statuses/{sha}","languages_url":"https://api.github.com/repos/inaka/lasse/languages","stargazers_url":"https://api.github.com/repos/inaka/lasse/stargazers","contributors_url":"https://api.github.com/repos/inaka/lasse/contributors","subscribers_url":"https://api.github.com/repos/inaka/lasse/subscribers","subscription_url":"https://api.github.com/repos/inaka/lasse/subscription","commits_url":"https://api.github.com/repos/inaka/lasse/commits{/sha}","git_commits_url":"https://api.github.com/repos/inaka/lasse/git/commits{/sha}","comments_url":"https://api.github.com/repos/inaka/lasse/comments{/number}","issue_comment_url":"https://api.github.com/repos/inaka/lasse/issues/comments/{number}","contents_url":"https://api.github.com/repos/inaka/lasse/contents/{+path}","compare_url":"https://api.github.com/repos/inaka/lasse/compare/{base}...{head}","merges_url":"https://api.github.com/repos/inaka/lasse/merges","archive_url":"https://api.github.com/repos/inaka/lasse/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/inaka/lasse/downloads","issues_url":"https://api.github.com/repos/inaka/lasse/issues{/number}","pulls_url":"https://api.github.com/repos/inaka/lasse/pulls{/number}","milestones_url":"https://api.github.com/repos/inaka/lasse/milestones{/number}","notifications_url":"https://api.github.com/repos/inaka/lasse/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/inaka/lasse/labels{/name}","releases_url":"https://api.github.com/repos/inaka/lasse/releases{/id}","created_at":"2014-06-03T17:24:57Z","updated_at":"2014-06-12T20:35:21Z","pushed_at":"2014-06-12T20:32:30Z","git_url":"git://github.com/inaka/lasse.git","ssh_url":"git@github.com:inaka/lasse.git","clone_url":"https://github.com/inaka/lasse.git","svn_url":"https://github.com/inaka/lasse","homepage":null,"size":256,"stargazers_count":0,"watchers_count":0,"language":"Erlang","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/inaka/lasse/pulls/8"},"html":{"href":"https://github.com/inaka/lasse/pull/8"},"issue":{"href":"https://api.github.com/repos/inaka/lasse/issues/8"},"comments":{"href":"https://api.github.com/repos/inaka/lasse/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/inaka/lasse/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/inaka/lasse/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/inaka/lasse/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/inaka/lasse/statuses/29c9262f50a8a216c5a961037c27546d7f2b25ad"}}}}