Browse Source

Update docs about async notifications; add notice test

Сергей Прохоров 8 years ago
parent
commit
ba60ef146f
3 changed files with 16 additions and 3 deletions
  1. 3 2
      README.md
  2. 2 1
      include/epgsql.hrl
  3. 11 0
      test/epgsql_tests.erl

+ 3 - 2
README.md

@@ -442,8 +442,9 @@ see `epgsql.hrl` for the record definition. `epgsql` functions may also return
 ## Server Notifications
 ## Server Notifications
 
 
 PostgreSQL may deliver two types of asynchronous message: "notices" in response
 PostgreSQL may deliver two types of asynchronous message: "notices" in response
-to notice and warning messages generated by the server, and "notifications" which
-are generated by the `LISTEN/NOTIFY` mechanism.
+to [notice and warning](https://www.postgresql.org/docs/current/static/plpgsql-errors-and-messages.html)
+messages generated by the server, and [notifications](https://www.postgresql.org/docs/current/static/sql-notify.html)
+which are generated by the `LISTEN/NOTIFY` mechanism.
 
 
 Passing the `{async, PidOrName}` option to `epgsql:connect/3` will result in these async
 Passing the `{async, PidOrName}` option to `epgsql:connect/3` will result in these async
 messages being sent to the specified pid or registered process, otherwise they will be dropped.
 messages being sent to the specified pid or registered process, otherwise they will be dropped.

+ 2 - 1
include/epgsql.hrl

@@ -15,7 +15,8 @@
 }).
 }).
 
 
 -record(error, {
 -record(error, {
-    severity :: fatal | error | atom(), %TODO: concretize
+    % see client_min_messages config option
+    severity :: debug | log | info | notice | warning | error | fatal | panic,
     code :: binary(),
     code :: binary(),
     codename :: atom(),
     codename :: atom(),
     message :: binary(),
     message :: binary(),

+ 11 - 0
test/epgsql_tests.erl

@@ -858,6 +858,17 @@ set_notice_receiver_test(Module) ->
           {ok, undefined} = Module:set_notice_receiver(C, Self),
           {ok, undefined} = Module:set_notice_receiver(C, Self),
           EnsureNotification(<<"test2">>),
           EnsureNotification(<<"test2">>),
 
 
+          %% test PL/PgSQL NOTICE
+          {ok, [], []} = Module:squery(
+                           C, ["DO $$ BEGIN RAISE WARNING 'test notice'; END $$;"]),
+          receive
+              {epgsql, C, {notice, #error{severity = warning,
+                                          code = <<"00000">>,
+                                          message = <<"test notice">>}}} -> ok
+          after
+              100 -> erlang:error(didnt_receive_notice)
+          end,
+
           % set registered pid
           % set registered pid
           Receiver = pg_notification_receiver,
           Receiver = pg_notification_receiver,
           register(Receiver, Self),
           register(Receiver, Self),