1
- var helper = require ( __dirname + '/test-helper' ) ;
1
+ var helper = require ( './test-helper' ) ;
2
+ const suite = new helper . Suite ( )
2
3
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 ) {
18
5
var client = helper . client ( ) ;
19
- client . query ( 'LISTEN boom' , assert . calls ( function ( ) {
6
+ client . query ( 'LISTEN boom' , assert . calls ( function ( ) {
20
7
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 ) {
23
11
//make sure PQfreemem doesn't invalidate string pointers
24
- setTimeout ( function ( ) {
12
+ setTimeout ( function ( ) {
25
13
assert . equal ( msg . channel , 'boom' ) ;
26
14
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 )
28
16
} , 100 )
29
-
30
17
} ) ;
31
- assert . emits ( otherClient , 'notification' , function ( msg ) {
18
+ assert . emits ( otherClient , 'notification' , function ( msg ) {
32
19
assert . equal ( msg . channel , 'boom' ) ;
33
- otherClient . end ( ) ;
20
+ otherClient . end ( ++ bothEmitted ? done : undefined ) ;
34
21
} ) ;
35
22
36
- client . query ( "NOTIFY boom, 'omg!'" , function ( err , q ) {
37
- if ( err ) {
23
+ client . query ( "NOTIFY boom, 'omg!'" , function ( err , q ) {
24
+ if ( err ) {
38
25
//notify not supported with payload on 8.x
39
26
client . query ( "NOTIFY boom" )
40
27
}
@@ -43,3 +30,26 @@ test('emits notify message', function() {
43
30
} ) ) ;
44
31
} )
45
32
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