1- var helper = require ( __dirname + '/test-helper' ) ;
1+ var helper = require ( './test-helper' ) ;
2+ const suite = new helper . Suite ( )
23
3- test ( 'emits notice message' , function ( ) {
4- //TODO this doesn't work on all versions of postgres
5- return false ;
6- var client = helper . client ( ) ;
7- client . query ( 'create temp table boom(id serial, size integer)' ) ;
8- assert . emits ( client , 'notice' , function ( notice ) {
9- assert . ok ( notice != null ) ;
10- //TODO ending connection after notice generates weird errors
11- process . nextTick ( function ( ) {
12- client . end ( ) ;
13- } )
14- } ) ;
15- } )
16-
17- test ( 'emits notify message' , function ( ) {
4+ suite . test ( 'emits notify message' , function ( done ) {
185 var client = helper . client ( ) ;
19- client . query ( 'LISTEN boom' , assert . calls ( function ( ) {
6+ client . query ( 'LISTEN boom' , assert . calls ( function ( ) {
207 var otherClient = helper . client ( ) ;
21- otherClient . query ( 'LISTEN boom' , assert . calls ( function ( ) {
22- assert . emits ( client , 'notification' , function ( msg ) {
8+ var bothEmitted = - 1
9+ otherClient . query ( 'LISTEN boom' , assert . calls ( function ( ) {
10+ assert . emits ( client , 'notification' , function ( msg ) {
2311 //make sure PQfreemem doesn't invalidate string pointers
24- setTimeout ( function ( ) {
12+ setTimeout ( function ( ) {
2513 assert . equal ( msg . channel , 'boom' ) ;
2614 assert . ok ( msg . payload == 'omg!' /*9.x*/ || msg . payload == '' /*8.x*/ , "expected blank payload or correct payload but got " + msg . message )
27- client . end ( )
15+ client . end ( ++ bothEmitted ? done : undefined )
2816 } , 100 )
29-
3017 } ) ;
31- assert . emits ( otherClient , 'notification' , function ( msg ) {
18+ assert . emits ( otherClient , 'notification' , function ( msg ) {
3219 assert . equal ( msg . channel , 'boom' ) ;
33- otherClient . end ( ) ;
20+ otherClient . end ( ++ bothEmitted ? done : undefined ) ;
3421 } ) ;
3522
36- client . query ( "NOTIFY boom, 'omg!'" , function ( err , q ) {
37- if ( err ) {
23+ client . query ( "NOTIFY boom, 'omg!'" , function ( err , q ) {
24+ if ( err ) {
3825 //notify not supported with payload on 8.x
3926 client . query ( "NOTIFY boom" )
4027 }
@@ -43,3 +30,26 @@ test('emits notify message', function() {
4330 } ) ) ;
4431} )
4532
33+
34+
35+ suite . test ( 'emits notice message' , function ( done ) {
36+ if ( helper . args . native ) {
37+ return console . error ( 'need to get notice message working on native' )
38+ }
39+ //TODO this doesn't work on all versions of postgres
40+ var client = helper . client ( ) ;
41+ const text = `
42+ DO language plpgsql $$
43+ BEGIN
44+ RAISE NOTICE 'hello, world!';
45+ END
46+ $$;
47+ `
48+ client . query ( text , ( ) => {
49+ client . end ( ) ;
50+ } ) ;
51+ assert . emits ( client , 'notice' , function ( notice ) {
52+ assert . ok ( notice != null ) ;
53+ done ( ) ;
54+ } ) ;
55+ } )
0 commit comments