Browse Source

switch to rebar3

Yuriy Zhloba 8 years ago
parent
commit
72766964c2
3 changed files with 40 additions and 47 deletions
  1. 13 20
      Makefile
  2. 4 4
      rebar.config
  3. 23 23
      test/epgsql_pool_SUITE.erl

+ 13 - 20
Makefile

@@ -1,29 +1,22 @@
-build-all:
-	rebar get-deps
-	rebar compile
-
-
 compile:
 compile:
-	rebar compile skip_deps=true
+	rebar3 compile
 
 
+eunit:
+	rebar3 eunit
 
 
-run:
-	erl -pa ebin -pa deps/*/ebin -boot start_sasl -s epgsql_pool test_run
+ct:
+	rebar3 ct
 
 
+tests: eunit ct
 
 
-tests:
-	rebar compile skip_deps=true
-	rebar eunit skip_deps=true
-	rebar ct skip_deps=true
+console:
+	erl -pa _build/default/lib/*/ebin -s epgsql_pool test_run
 
 
+d:
+	rebar3 dialyzer
 
 
 clean:
 clean:
-	rebar clean
-
+	rebar3 clean
 
 
-ct-clean:
-	rm -rf logs/*
-
-
-d:
-	dialyzer --src -I include src
+clean-all:
+	rm -rf _build

+ 4 - 4
rebar.config

@@ -1,11 +1,11 @@
 %%-*- mode: erlang -*-
 %%-*- mode: erlang -*-
 
 
-{erl_opts, [debug_info,
+{erl_opts, [
             warn_missing_spec
             warn_missing_spec
            ]}.
            ]}.
 
 
 {deps, [
 {deps, [
-        {pooler, ".*", {git, "https://github.com/seth/pooler", {tag, "1.5.2"}}},
-        {epgsql, ".*", {git, "https://github.com/epgsql/epgsql", {tag, "3.2.0"}}},
-        {herd, ".*", {git, "https://github.com/wgnet/herd", {tag, "1.3"}}}
+        {pooler, {git, "https://github.com/seth/pooler", {tag, "1.5.2"}}},
+        {epgsql, {git, "https://github.com/epgsql/epgsql", {tag, "3.2.0"}}},
+        {herd, {git, "https://github.com/wgnet/herd", {tag, "1.3"}}}
        ]}.
        ]}.

+ 23 - 23
test/epgsql_pool_SUITE.erl

@@ -59,16 +59,16 @@ query_test(Config) ->
     WaitForRows = lists:map(fun({{Id}, Title}) -> {Id, Title} end,
     WaitForRows = lists:map(fun({{Id}, Title}) -> {Id, Title} end,
                             lists:zip(Ids, [<<"cat 1">>, <<"cat 2">>, <<"cat 3">>])),
                             lists:zip(Ids, [<<"cat 1">>, <<"cat 2">>, <<"cat 3">>])),
     {ok, _, Rows} = epgsql_pool:query(my_pool, "SELECT id, title FROM category ORDER by id ASC"),
     {ok, _, Rows} = epgsql_pool:query(my_pool, "SELECT id, title FROM category ORDER by id ASC"),
-    ct:pal("Rows ~p", [Rows]),
+    ct:log("Rows ~p", [Rows]),
     ?assertEqual(WaitForRows, Rows),
     ?assertEqual(WaitForRows, Rows),
 
 
     [{Id1}, {Id2} | _] = Ids,
     [{Id1}, {Id2} | _] = Ids,
     {ok, _, Rows2} = epgsql_pool:query(my_pool, "SELECT id, title FROM category WHERE id = $1 OR id = $2 ORDER BY id ASC", [Id1, Id2]),
     {ok, _, Rows2} = epgsql_pool:query(my_pool, "SELECT id, title FROM category WHERE id = $1 OR id = $2 ORDER BY id ASC", [Id1, Id2]),
-    ct:pal("Rows2 ~p", [Rows2]),
+    ct:log("Rows2 ~p", [Rows2]),
     ?assertEqual([{Id1, <<"cat 1">>}, {Id2, <<"cat 2">>}], Rows2),
     ?assertEqual([{Id1, <<"cat 1">>}, {Id2, <<"cat 2">>}], Rows2),
 
 
     {error, Error} = epgsql_pool:query(my_pool, "SELECT id, title FROM some_table"),
     {error, Error} = epgsql_pool:query(my_pool, "SELECT id, title FROM some_table"),
-    ct:pal("Error:~p", [Error]),
+    ct:log("Error:~p", [Error]),
     ?assertMatch(#error{severity = error, message = <<"relation \"some_table\" does not exist">>}, Error),
     ?assertMatch(#error{severity = error, message = <<"relation \"some_table\" does not exist">>}, Error),
     ok.
     ok.
 
 
@@ -80,7 +80,7 @@ squery_test(Config) ->
     WaitForRows = lists:map(fun({{Id}, Title}) -> {Id, Title} end,
     WaitForRows = lists:map(fun({{Id}, Title}) -> {Id, Title} end,
                             lists:zip(Ids, [<<"cat 1">>, <<"cat 2">>, <<"cat 3">>])),
                             lists:zip(Ids, [<<"cat 1">>, <<"cat 2">>, <<"cat 3">>])),
     {ok, _, Rows} = epgsql_pool:squery(my_pool, "SELECT id, title FROM category ORDER by id ASC"),
     {ok, _, Rows} = epgsql_pool:squery(my_pool, "SELECT id, title FROM category ORDER by id ASC"),
-    ct:pal("Rows ~p", [Rows]),
+    ct:log("Rows ~p", [Rows]),
     ?assertEqual(WaitForRows, Rows),
     ?assertEqual(WaitForRows, Rows),
 
 
     ?assertMatch([{ok, _, [{<<"1">>}]}, {ok, _, [{<<"2">>}]}],
     ?assertMatch([{ok, _, [{<<"1">>}]}, {ok, _, [{<<"2">>}]}],
@@ -94,7 +94,7 @@ transaction_test(Config) ->
     {FirstCatId, CatIds2, ItemIds2} =
     {FirstCatId, CatIds2, ItemIds2} =
         epgsql_pool:transaction(my_pool,
         epgsql_pool:transaction(my_pool,
                                 fun(Worker) ->
                                 fun(Worker) ->
-                                        ct:pal("worker:~p", [Worker]),
+                                        ct:log("worker:~p", [Worker]),
                                         {ok, 3, _, CatIds0} =
                                         {ok, 3, _, CatIds0} =
                                             epgsql_pool:query(Worker,
                                             epgsql_pool:query(Worker,
                                                               "INSERT INTO category (title) "
                                                               "INSERT INTO category (title) "
@@ -112,26 +112,26 @@ transaction_test(Config) ->
                                 end),
                                 end),
     WaitForCats = lists:zip(CatIds2, [<<"cat 4">>, <<"cat 5">>, <<"cat 6">>]),
     WaitForCats = lists:zip(CatIds2, [<<"cat 4">>, <<"cat 5">>, <<"cat 6">>]),
     {ok, _, CatRows} = epgsql_pool:query(my_pool, "SELECT id, title FROM category ORDER by id ASC"),
     {ok, _, CatRows} = epgsql_pool:query(my_pool, "SELECT id, title FROM category ORDER by id ASC"),
-    ct:pal("CatRows ~p", [CatRows]),
+    ct:log("CatRows ~p", [CatRows]),
     ?assertEqual(WaitForCats, CatRows),
     ?assertEqual(WaitForCats, CatRows),
 
 
     WaitForItems = lists:map(fun({ItemId, {Title, Num}}) -> {ItemId, FirstCatId, Title, Num} end,
     WaitForItems = lists:map(fun({ItemId, {Title, Num}}) -> {ItemId, FirstCatId, Title, Num} end,
                              lists:zip(ItemIds2, [{<<"item 1">>, 5}, {<<"item 2">>, 7}])),
                              lists:zip(ItemIds2, [{<<"item 1">>, 5}, {<<"item 2">>, 7}])),
     {ok, _, ItemRows} = epgsql_pool:query(my_pool, ?SELECT_ITEMS_QUERY),
     {ok, _, ItemRows} = epgsql_pool:query(my_pool, ?SELECT_ITEMS_QUERY),
-    ct:pal("ItemRows ~p", [ItemRows]),
+    ct:log("ItemRows ~p", [ItemRows]),
     ?assertEqual(WaitForItems, ItemRows),
     ?assertEqual(WaitForItems, ItemRows),
 
 
     try
     try
         epgsql_pool:transaction(my_pool,
         epgsql_pool:transaction(my_pool,
                                 fun(Worker) ->
                                 fun(Worker) ->
-                                        ct:pal("worker:~p", [Worker]),
+                                        ct:log("worker:~p", [Worker]),
                                         {ok, 2} =
                                         {ok, 2} =
                                             epgsql_pool:query(Worker,
                                             epgsql_pool:query(Worker,
                                                               "INSERT INTO item (category_id, title, num) "
                                                               "INSERT INTO item (category_id, title, num) "
                                                               "VALUES ($1, 'item 3', 55), ($1, 'item 4', 77) ",
                                                               "VALUES ($1, 'item 3', 55), ($1, 'item 4', 77) ",
                                                               [FirstCatId]),
                                                               [FirstCatId]),
                                         {ok, _, ItemRows2} = epgsql_pool:query(Worker, ?SELECT_ITEMS_QUERY),
                                         {ok, _, ItemRows2} = epgsql_pool:query(Worker, ?SELECT_ITEMS_QUERY),
-                                        ct:pal("ItemRows2 ~p", [ItemRows2]),
+                                        ct:log("ItemRows2 ~p", [ItemRows2]),
                                         ?assertMatch([{_, FirstCatId, <<"item 1">>, 5},
                                         ?assertMatch([{_, FirstCatId, <<"item 1">>, 5},
                                                       {_, FirstCatId, <<"item 2">>, 7},
                                                       {_, FirstCatId, <<"item 2">>, 7},
                                                       {_, FirstCatId, <<"item 3">>, 55},
                                                       {_, FirstCatId, <<"item 3">>, 55},
@@ -151,33 +151,33 @@ transaction_test(Config) ->
 reconnect_test(Config) ->
 reconnect_test(Config) ->
     Worker = pooler:take_member(my_pool, 1000),
     Worker = pooler:take_member(my_pool, 1000),
     [state, my_pool, #epgsql_connection{sock = Sock1} | _]= tuple_to_list(sys:get_state(Worker)),
     [state, my_pool, #epgsql_connection{sock = Sock1} | _]= tuple_to_list(sys:get_state(Worker)),
-    ct:pal("Worker: ~p, sock: ~p", [Worker, Sock1]),
+    ct:log("Worker: ~p, sock: ~p", [Worker, Sock1]),
 
 
     R1 = epgsql_pool:query(Worker, ?SELECT_ITEMS_QUERY),
     R1 = epgsql_pool:query(Worker, ?SELECT_ITEMS_QUERY),
-    ct:pal("first query ~p", [R1]),
+    ct:log("first query ~p", [R1]),
     {ok, _, []} = R1,
     {ok, _, []} = R1,
 
 
-    ct:pal("~p close_connection", [Sock1]),
+    ct:log("~p close_connection", [Sock1]),
     exit(Sock1, close_connection),
     exit(Sock1, close_connection),
 
 
     R2 = epgsql_pool:query(Worker, "select * from item"),
     R2 = epgsql_pool:query(Worker, "select * from item"),
-    ct:pal("second query goes immediatelly ~p", [R2]),
+    ct:log("second query goes immediatelly ~p", [R2]),
     {error, no_connection} = R2,
     {error, no_connection} = R2,
 
 
     timer:sleep(50),
     timer:sleep(50),
 
 
     R3 = epgsql_pool:query(Worker, "select * from item"),
     R3 = epgsql_pool:query(Worker, "select * from item"),
-    ct:pal("third query goes after 50 ms ~p", [R3]),
+    ct:log("third query goes after 50 ms ~p", [R3]),
     {error, no_connection} = R3,
     {error, no_connection} = R3,
 
 
     timer:sleep(150),
     timer:sleep(150),
 
 
     R4 = epgsql_pool:query(Worker, "select * from item"),
     R4 = epgsql_pool:query(Worker, "select * from item"),
-    ct:pal("fouth query goes after 200 ms ~p", [R4]),
+    ct:log("fouth query goes after 200 ms ~p", [R4]),
     {ok, _, []} = R4,
     {ok, _, []} = R4,
 
 
     [state, my_pool, #epgsql_connection{sock = Sock2} | _]= tuple_to_list(sys:get_state(Worker)),
     [state, my_pool, #epgsql_connection{sock = Sock2} | _]= tuple_to_list(sys:get_state(Worker)),
-    ct:pal("Worker: ~p, sock: ~p", [Worker, Sock2]),
+    ct:log("Worker: ~p, sock: ~p", [Worker, Sock2]),
 
 
     ?assertNotEqual(Sock1, Sock2),
     ?assertNotEqual(Sock1, Sock2),
     ok.
     ok.
@@ -185,22 +185,22 @@ reconnect_test(Config) ->
 
 
 timeout_test(_Config) ->
 timeout_test(_Config) ->
     Res1 = epgsql_pool:query(my_pool, "SELECT pg_sleep(1)", [], [{timeout, 2000}]),
     Res1 = epgsql_pool:query(my_pool, "SELECT pg_sleep(1)", [], [{timeout, 2000}]),
-    ct:pal("Res1:~p", [Res1]),
+    ct:log("Res1:~p", [Res1]),
     ?assertMatch({ok, _, _}, Res1),
     ?assertMatch({ok, _, _}, Res1),
 
 
     Res2 = epgsql_pool:query(my_pool, "SELECT pg_sleep(1)", [], [{timeout, 500}]),
     Res2 = epgsql_pool:query(my_pool, "SELECT pg_sleep(1)", [], [{timeout, 500}]),
-    ct:pal("Res2:~p", [Res2]),
+    ct:log("Res2:~p", [Res2]),
     ?assertEqual({error, timeout}, Res2),
     ?assertEqual({error, timeout}, Res2),
 
 
     Worker = pooler:take_member(my_pool, 1000),
     Worker = pooler:take_member(my_pool, 1000),
 
 
     Res3 = epgsql_pool:query(Worker, "SELECT pg_sleep(100)", [], [{timeout, 500}]),
     Res3 = epgsql_pool:query(Worker, "SELECT pg_sleep(100)", [], [{timeout, 500}]),
-    ct:pal("Res3:~p", [Res3]),
+    ct:log("Res3:~p", [Res3]),
     ?assertEqual({error, timeout}, Res3),
     ?assertEqual({error, timeout}, Res3),
 
 
     %% check worker and connection able to perform query
     %% check worker and connection able to perform query
     Res4 = epgsql_pool:query(Worker, "SELECT * FROM item", [], [{timeout, 500}]),
     Res4 = epgsql_pool:query(Worker, "SELECT * FROM item", [], [{timeout, 500}]),
-    ct:pal("Res4:~p", [Res4]),
+    ct:log("Res4:~p", [Res4]),
     ?assertMatch({ok, _, _}, Res4),
     ?assertMatch({ok, _, _}, Res4),
 
 
     ok.
     ok.
@@ -210,19 +210,19 @@ validate_connection_params_test(_Config) ->
     Params1 = #epgsql_connection_params{host = "localhost", port = 5432,
     Params1 = #epgsql_connection_params{host = "localhost", port = 5432,
                                         username = "test", password = "test", database = "testdb"},
                                         username = "test", password = "test", database = "testdb"},
     Res1 = epgsql_pool:validate_connection_params(Params1),
     Res1 = epgsql_pool:validate_connection_params(Params1),
-    ct:pal("Res1: ~p", [Res1]),
+    ct:log("Res1: ~p", [Res1]),
     ?assertEqual(ok, Res1),
     ?assertEqual(ok, Res1),
 
 
     Params2 = #epgsql_connection_params{host = "localhost", port = 5432,
     Params2 = #epgsql_connection_params{host = "localhost", port = 5432,
                                         username = "test", password = "some", database = "testdb"},
                                         username = "test", password = "some", database = "testdb"},
     Res2 = epgsql_pool:validate_connection_params(Params2),
     Res2 = epgsql_pool:validate_connection_params(Params2),
-    ct:pal("Res2: ~p", [Res2]),
+    ct:log("Res2: ~p", [Res2]),
     ?assertEqual({error,invalid_password}, Res2),
     ?assertEqual({error,invalid_password}, Res2),
 
 
     Params3 = #epgsql_connection_params{host = "localhost", port = 5432,
     Params3 = #epgsql_connection_params{host = "localhost", port = 5432,
                                         username = "test", password = "test", database = "some"},
                                         username = "test", password = "test", database = "some"},
     {error, Res3} = epgsql_pool:validate_connection_params(Params3),
     {error, Res3} = epgsql_pool:validate_connection_params(Params3),
-    ct:pal("Res3: ~p", [Res3]),
+    ct:log("Res3: ~p", [Res3]),
     ?assertMatch(#error{
     ?assertMatch(#error{
                     severity = fatal,
                     severity = fatal,
                     code = <<"3D000">>,
                     code = <<"3D000">>,