Skip to content

Commit

Permalink
bump version to v2.6.0, make check_for_gen_tcp_fix a test
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum committed Apr 15, 2013
1 parent 56a32a0 commit 92b8f5b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 32 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
@@ -1,3 +1,8 @@
Version 2.6.0 released 2013-04-15

* Enable R15B gen_tcp workaround only on R15B
https://github.com/mochi/mochiweb/pull/107

Version 2.5.0 released 2013-03-04

* Replace now() with os:timestamp() in acceptor (optimization)
Expand Down
3 changes: 1 addition & 2 deletions rebar.config
@@ -1,7 +1,6 @@
% -*- mode: erlang -*-
{erl_opts, [debug_info,
{platform_define, "(R14|R16)", 'gen_tcp_fix'}
]}.
{platform_define, "R15", 'gen_tcp_r15b_workaround'}]}.
{cover_enabled, true}.
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
{dialyzer_opts, [{warnings, [no_return,
Expand Down
28 changes: 0 additions & 28 deletions scripts/check_for_gen_tcp_fix.erl

This file was deleted.

2 changes: 1 addition & 1 deletion src/mochiweb.app.src
@@ -1,7 +1,7 @@
%% This is generated from src/mochiweb.app.src
{application, mochiweb,
[{description, "MochiMedia Web Server"},
{vsn, "2.5.0"},
{vsn, "2.6.0"},
{modules, []},
{registered, []},
{env, []},
Expand Down
2 changes: 1 addition & 1 deletion src/mochiweb_http.erl
Expand Up @@ -50,7 +50,7 @@ loop(Socket, Body) ->
ok = mochiweb_socket:setopts(Socket, [{packet, http}]),
request(Socket, Body).

-ifndef(gen_tcp_fix).
-ifdef(gen_tcp_r15b_workaround).
-define(R15B_GEN_TCP_FIX, {tcp_error,_,emsgsize} ->
% R15B02 returns this then closes the socket, so close and exit
mochiweb_socket:close(Socket),
Expand Down
45 changes: 45 additions & 0 deletions test/mochiweb_http_tests.erl
@@ -0,0 +1,45 @@
-module(mochiweb_http_tests).
-include_lib("eunit/include/eunit.hrl").

-ifdef(gen_tcp_r15b_workaround).
-define(SHOULD_HAVE_BUG, true).
-else.
-define(SHOULD_HAVE_BUG, false).
-endif.

has_acceptor_bug_test_() ->
{setup,
fun start_server/0,
fun mochiweb_http:stop/1,
fun has_acceptor_bug_tests/1}.

start_server() ->
application:start(inets),
{ok, Pid} = mochiweb_http:start_link([{port, 0},
{loop, fun responder/1}]),
Pid.

has_acceptor_bug_tests(Server) ->
Port = mochiweb_socket_server:get(Server, port),
[{"1000 should be fine even with the bug",
?_assertEqual(false, has_bug(Port, 1000))},
{"10000 should trigger the bug if present",
?_assertEqual(?SHOULD_HAVE_BUG, has_bug(Port, 10000))}].

responder(Req) ->
Req:respond({200,
[{"Content-Type", "text/html"}],
["<html><body>Hello</body></html>"]}).

has_bug(Port, Len) ->
case
httpc:request(get, {"http://127.0.0.1:" ++ integer_to_list(Port) ++ "/",
[{"X-Random", lists:duplicate(Len, $a)}]}, [], [])
of
{error, socket_closed_remotely} ->
true;
{ok, {{"HTTP/1.1", 200, "OK"}, _, "<html><body>Hello</body></html>"}} ->
false;
{ok, {{"HTTP/1.1", 400, "Bad Request"}, _, []}} ->
false
end.

0 comments on commit 92b8f5b

Please sign in to comment.