Browse Source

Use macro while testing and update README.md

Enid Gjoleka 5 years ago
parent
commit
bfba4ea0d7
2 changed files with 24 additions and 10 deletions
  1. 1 1
      README.md
  2. 23 9
      test/epgsql_SUITE.erl

+ 1 - 1
README.md

@@ -451,7 +451,7 @@ epgsql:cancel(connection()) -> ok.
 
 PostgreSQL protocol supports [cancellation](https://www.postgresql.org/docs/current/protocol-flow.html#id-1.10.5.7.9)
 of currently executing command. `cancel/1` sends a cancellation request via the
-new temporary TCP connection asynchronously, it doesn't await for the command to
+new temporary TCP/TLS_over_TCP connection asynchronously, it doesn't await for the command to
 be cancelled. Instead, client should expect to get
 `{error, #error{code = <<"57014">>, codename = query_canceled}}` back from
 the command that was cancelled. However, normal response can still be received as well.

+ 23 - 9
test/epgsql_SUITE.erl

@@ -173,6 +173,16 @@ end_per_group(_GroupName, _Config) ->
                  {routine, _} | _]
         }}).
 
+-define(QUERY_CANCELED, {error, #error{
+        severity = error,
+        code = <<"57014">>,
+        codename = query_canceled,
+        message = <<"canceling statement due to user request">>,
+        extra = [{file, <<"postgres.c">>},
+                 {line, _},
+                 {routine, _} | _]
+        }}).
+
 %% From uuid.erl in http://gitorious.org/avtobiff/erlang-uuid
 uuid_to_bin_string(<<U0:32, U1:16, U2:16, U3:16, U4:48>>) ->
     iolist_to_binary(io_lib:format(
@@ -290,15 +300,17 @@ cancel_query_for_connection_with_ssl(Config) ->
     Module = ?config(module, Config),
     {Host, Port} = epgsql_ct:connection_data(Config),
     Module = ?config(module, Config),
-    Args2 = [{port, Port}, {database, "epgsql_test_db1"} | [ {ssl, true}, {timeout, 1000} ]],
+    Args2 = [ {port, Port}, {database, "epgsql_test_db1"}
+            | [ {ssl, true}
+              , {timeout, 1000} ]
+            ],
     {ok, C} = Module:connect(Host, "epgsql_test", Args2),
     ?assertMatch({ok, _Cols, [{true}]},
                 Module:equery(C, "select ssl_is_used()")),
     process_flag(trap_exit, true),
     Self = self(),
     spawn_link(fun() ->
-                   ?assertMatch({error, #error{codename = query_canceled}},
-                                Module:equery(C, "SELECT pg_sleep(5)")),
+                   ?assertMatch(?QUERY_CANCELED, Module:equery(C, "SELECT pg_sleep(5)")),
                    Self ! done
                end),
     %% this will never match but introduces 1 second latency needed
@@ -313,20 +325,21 @@ cancel_query_for_connection_with_ssl(Config) ->
             epgsql:close(C),
             ?assert(false)
         end
-    end.
+    end,
+    epgsql_ct:flush().
 
 cancel_query_for_connection_with_gen_tcp(Config) ->
     Module = ?config(module, Config),
     {Host, Port} = epgsql_ct:connection_data(Config),
     Module = ?config(module, Config),
-    Args2 = [{port, Port}, {database, "epgsql_test_db1"} | [ {timeout, 1000} ]],
+    Args2 = [ {port, Port}, {database, "epgsql_test_db1"}
+            | [ {timeout, 1000} ]
+            ],
     {ok, C} = Module:connect(Host, "epgsql_test", Args2),
-  
     process_flag(trap_exit, true),
     Self = self(),
     spawn_link(fun() ->
-                   ?assertMatch({error, #error{codename = query_canceled}},
-                                Module:equery(C, "SELECT pg_sleep(5)")),
+                   ?assertMatch(?QUERY_CANCELED, Module:equery(C, "SELECT pg_sleep(5)")),
                    Self ! done
                end),
     %% this is will never match but it introduces the 1 second latency needed
@@ -341,7 +354,8 @@ cancel_query_for_connection_with_gen_tcp(Config) ->
             epgsql:close(C),
             ?assert(false)
         end
-    end.
+    end,
+    epgsql_ct:flush().
 
 connect_with_client_cert(Config) ->
     Module = ?config(module, Config),