@@ -17,14 +17,14 @@ describe('debug', () => {
17
17
const smallFileName = path . join ( os . tmpdir ( ) , 'smallLocalInfileDebug.txt' ) ;
18
18
19
19
let permitLocalInfile = true ;
20
- let tmpLogFile = path . join ( os . tmpdir ( ) , 'combined.txt' ) ;
21
20
let logger ;
22
21
let setNameAddition = 0 ;
22
+ let fileIncrement = 0 ;
23
23
24
24
before ( async function ( ) {
25
25
if ( ! isXpand ( ) ) {
26
26
try {
27
- fs . unlinkSync ( tmpLogFile ) ;
27
+ fs . unlinkSync ( path . join ( os . tmpdir ( ) , 'combined*.txt' ) ) ;
28
28
} catch ( e ) { }
29
29
const rows = await shareConn . query ( 'select @@local_infile' ) ;
30
30
permitLocalInfile = rows [ 0 ] [ '@@local_infile' ] === 1 || rows [ 0 ] [ '@@local_infile' ] === 1n ;
@@ -38,6 +38,7 @@ describe('debug', () => {
38
38
} ) ;
39
39
40
40
beforeEach ( async function ( ) {
41
+ let tmpLogFile = path . join ( os . tmpdir ( ) , 'combined' + ++ fileIncrement + '.txt' ) ;
41
42
logger = winston . createLogger ( {
42
43
transports : [ new winston . transports . File ( { filename : tmpLogFile } ) ]
43
44
} ) ;
@@ -46,6 +47,7 @@ describe('debug', () => {
46
47
47
48
//ensure that debug from previous test are written to console
48
49
afterEach ( async function ( ) {
50
+ let tmpLogFile = path . join ( os . tmpdir ( ) , 'combined' + fileIncrement + '.txt' ) ;
49
51
await closeLogger ( logger ) ;
50
52
try {
51
53
fs . unlinkSync ( tmpLogFile ) ;
@@ -59,120 +61,98 @@ describe('debug', () => {
59
61
}
60
62
} ) ;
61
63
62
- it ( 'select request debug' , function ( done ) {
63
- testQueryDebug ( false , done ) ;
64
+ it ( 'select request debug' , async function ( ) {
65
+ await testQueryDebug ( false ) ;
64
66
} ) ;
65
67
66
- it ( 'select request debug compress' , function ( done ) {
68
+ it ( 'select request debug compress' , async function ( ) {
67
69
if ( isXpand ( ) ) this . skip ( ) ;
68
- testQueryDebug ( true , done ) ;
70
+ await testQueryDebug ( true ) ;
69
71
} ) ;
70
72
71
- function testQueryDebug ( compress , done ) {
72
- base
73
- . createConnection ( {
74
- compress : compress ,
75
- prepareCacheLength : 0 ,
76
- logger : {
77
- network : null ,
78
- query : ( msg ) => logger . info ( msg ) ,
79
- error : ( msg ) => logger . info ( msg )
80
- }
81
- } )
82
- . then ( ( conn ) => {
83
- conn
84
- . query ( 'CREATE TABLE debugVoid (val int)' )
85
- . then ( ( ) => {
86
- if ( compress && ! isMaxscale ( ) && process . env . srv !== 'skysql' && process . env . srv !== 'skysql-ha' ) {
87
- conn . debugCompress ( ( msg ) => logger . info ( msg ) ) ;
88
- } else {
89
- conn . debug ( ( msg ) => logger . info ( msg ) ) ;
90
- }
91
- return conn . query ( 'SELECT 2' ) ;
92
- } )
93
- . then ( ( ) => {
94
- if ( compress && ! isMaxscale ( ) && process . env . srv !== 'skysql' && process . env . srv !== 'skysql-ha' ) {
95
- conn . debugCompress ( false ) ;
96
- } else {
97
- conn . debug ( false ) ;
98
- }
99
- return conn . query ( 'SELECT 3' ) ;
100
- } )
101
- . then ( ( ) => {
102
- return conn . prepare ( 'SELECT ?' ) ;
103
- } )
104
- . then ( ( prepare ) => {
105
- return prepare . execute ( [ 't' ] ) . then ( ( res ) => prepare . close ( ) ) ;
106
- } )
107
- . then ( ( ) => {
108
- return conn . batch ( 'INSERT INTO debugVoid VALUES (?)' , [ [ 1 ] , [ 2 ] ] ) ;
109
- } )
110
- . then ( ( ) => {
111
- return conn . end ( ) ;
112
- } )
113
- . then ( ( ) => {
114
- //wait 100ms to ensure stream has been written
115
- setTimeout ( ( ) => {
116
- const serverVersion = conn . serverVersion ( ) ;
117
- if ( isMaxscale ( ) || process . env . srv === 'skysql' || process . env . srv === 'skysql-ha' ) compress = false ;
118
- const rangeWithEOF = compress ? [ 1500 , 2000 ] : [ 1800 , 4250 ] ;
119
- const rangeWithoutEOF = compress ? [ 1500 , 2000 ] : [ 2350 , 3250 ] ;
120
- const data = fs . readFileSync ( tmpLogFile , 'utf8' ) ;
121
- console . log ( data ) ;
122
- assert . isTrue ( data . includes ( 'QUERY: SELECT 3' ) ) ;
123
- assert . isTrue ( data . includes ( 'PREPARE:' ) ) ;
124
- assert . isTrue ( data . includes ( 'EXECUTE:' ) ) ;
125
- assert . isTrue ( data . includes ( "SELECT ? - parameters:['t']" ) ) ;
126
- assert . isTrue ( data . includes ( 'CLOSE PREPARE:' ) ) ;
127
- if ( conn . info . isMariaDB ( ) && conn . info . hasMinVersion ( 10 , 2 , 2 ) ) {
128
- assert . isTrue ( data . includes ( 'BULK:' ) ) ;
129
- assert . isTrue ( data . includes ( 'INSERT INTO debugVoid VALUES (?) - parameters:[[1],[2]]' ) ) ;
130
- }
131
- assert . isTrue ( data . includes ( 'QUIT' ) ) ;
132
- if (
133
- ( ( conn . info . isMariaDB ( ) && conn . info . hasMinVersion ( 10 , 2 , 2 ) ) ||
134
- ( ! conn . info . isMariaDB ( ) && conn . info . hasMinVersion ( 5 , 7 , 5 ) ) ) &&
135
- ! isMaxscale ( ) &&
136
- process . env . srv !== 'skysql' &&
137
- process . env . srv !== 'skysql-ha'
138
- ) {
139
- assert (
140
- data . length > rangeWithoutEOF [ 0 ] && data . length < rangeWithoutEOF [ 1 ] ,
141
- 'wrong data length : ' +
142
- data . length +
143
- ' expected value between ' +
144
- rangeWithoutEOF [ 0 ] +
145
- ' and ' +
146
- rangeWithoutEOF [ 1 ] +
147
- '.' +
148
- '\n server version : ' +
149
- serverVersion +
150
- '\n data :\n' +
151
- data
152
- ) ;
153
- } else {
154
- //EOF Packet make exchange bigger
155
- assert (
156
- data . length > rangeWithEOF [ 0 ] && data . length < rangeWithEOF [ 1 ] ,
157
- 'wrong data length : ' +
158
- data . length +
159
- ' expected value between ' +
160
- rangeWithEOF [ 0 ] +
161
- ' and ' +
162
- rangeWithEOF [ 1 ] +
163
- '.' +
164
- '\n server version : ' +
165
- serverVersion +
166
- '\n data :\n' +
167
- data
168
- ) ;
169
- }
170
- done ( ) ;
171
- } , 100 ) ;
172
- } )
173
- . catch ( done ) ;
174
- } )
175
- . catch ( done ) ;
73
+ async function testQueryDebug ( compress ) {
74
+ const conn = await base . createConnection ( {
75
+ compress : compress ,
76
+ prepareCacheLength : 0 ,
77
+ logger : {
78
+ network : null ,
79
+ query : ( msg ) => logger . info ( msg ) ,
80
+ error : ( msg ) => logger . info ( msg )
81
+ }
82
+ } ) ;
83
+ await conn . query ( 'CREATE TABLE debugVoid (val int)' ) ;
84
+ if ( compress && ! isMaxscale ( ) && process . env . srv !== 'skysql' && process . env . srv !== 'skysql-ha' ) {
85
+ conn . debugCompress ( ( msg ) => logger . info ( msg ) ) ;
86
+ } else {
87
+ conn . debug ( ( msg ) => logger . info ( msg ) ) ;
88
+ }
89
+ await conn . query ( 'SELECT 2' ) ;
90
+ if ( compress && ! isMaxscale ( ) && process . env . srv !== 'skysql' && process . env . srv !== 'skysql-ha' ) {
91
+ conn . debugCompress ( false ) ;
92
+ } else {
93
+ conn . debug ( false ) ;
94
+ }
95
+ await conn . query ( 'SELECT 3' ) ;
96
+ const prepare = await conn . prepare ( 'SELECT ?' ) ;
97
+ await prepare . execute ( [ 't' ] ) . then ( ( res ) => prepare . close ( ) ) ;
98
+ await conn . batch ( 'INSERT INTO debugVoid VALUES (?)' , [ [ 1 ] , [ 2 ] ] ) ;
99
+ conn . end ( ) ;
100
+ //wait 100ms to ensure stream has been written
101
+ await new Promise ( ( resolve ) => new setTimeout ( resolve , 100 ) ) ;
102
+ const serverVersion = conn . serverVersion ( ) ;
103
+ if ( isMaxscale ( ) || process . env . srv === 'skysql' || process . env . srv === 'skysql-ha' ) compress = false ;
104
+ const rangeWithEOF = compress ? [ 1500 , 2000 ] : [ 1800 , 4250 ] ;
105
+ const rangeWithoutEOF = compress ? [ 1500 , 2000 ] : [ 2350 , 3250 ] ;
106
+ const data = fs . readFileSync ( path . join ( os . tmpdir ( ) , 'combined' + fileIncrement + '.txt' ) , 'utf8' ) ;
107
+ console . log ( data ) ;
108
+ assert . isTrue ( data . includes ( 'QUERY: SELECT 3' ) ) ;
109
+ assert . isTrue ( data . includes ( 'PREPARE:' ) ) ;
110
+ assert . isTrue ( data . includes ( 'EXECUTE:' ) ) ;
111
+ assert . isTrue ( data . includes ( "SELECT ? - parameters:['t']" ) ) ;
112
+ assert . isTrue ( data . includes ( 'CLOSE PREPARE:' ) ) ;
113
+ if ( conn . info . isMariaDB ( ) && conn . info . hasMinVersion ( 10 , 2 , 2 ) ) {
114
+ assert . isTrue ( data . includes ( 'BULK:' ) ) ;
115
+ assert . isTrue ( data . includes ( 'INSERT INTO debugVoid VALUES (?) - parameters:[[1],[2]]' ) ) ;
116
+ }
117
+ assert . isTrue ( data . includes ( 'QUIT' ) ) ;
118
+ if (
119
+ ( ( conn . info . isMariaDB ( ) && conn . info . hasMinVersion ( 10 , 2 , 2 ) ) ||
120
+ ( ! conn . info . isMariaDB ( ) && conn . info . hasMinVersion ( 5 , 7 , 5 ) ) ) &&
121
+ ! isMaxscale ( ) &&
122
+ process . env . srv !== 'skysql' &&
123
+ process . env . srv !== 'skysql-ha'
124
+ ) {
125
+ assert (
126
+ data . length > rangeWithoutEOF [ 0 ] && data . length < rangeWithoutEOF [ 1 ] ,
127
+ 'wrong data length : ' +
128
+ data . length +
129
+ ' expected value between ' +
130
+ rangeWithoutEOF [ 0 ] +
131
+ ' and ' +
132
+ rangeWithoutEOF [ 1 ] +
133
+ '.' +
134
+ '\n server version : ' +
135
+ serverVersion +
136
+ '\n data :\n' +
137
+ data
138
+ ) ;
139
+ } else {
140
+ //EOF Packet make exchange bigger
141
+ assert (
142
+ data . length > rangeWithEOF [ 0 ] && data . length < rangeWithEOF [ 1 ] ,
143
+ 'wrong data length : ' +
144
+ data . length +
145
+ ' expected value between ' +
146
+ rangeWithEOF [ 0 ] +
147
+ ' and ' +
148
+ rangeWithEOF [ 1 ] +
149
+ '.' +
150
+ '\n server version : ' +
151
+ serverVersion +
152
+ '\n data :\n' +
153
+ data
154
+ ) ;
155
+ }
176
156
}
177
157
178
158
it ( 'select big request (compressed data) debug' , function ( done ) {
@@ -191,7 +171,7 @@ describe('debug', () => {
191
171
. end ( )
192
172
. then ( ( ) => {
193
173
const serverVersion = conn . serverVersion ( ) ;
194
- const data = fs . readFileSync ( tmpLogFile , 'utf8' ) ;
174
+ const data = fs . readFileSync ( path . join ( os . tmpdir ( ) , 'combined' + fileIncrement + '.txt' ) , 'utf8' ) ;
195
175
let range = [ 8900 , 12000 + setNameAddition ] ;
196
176
assert (
197
177
data . length > range [ 0 ] && data . length < range [ 1 ] ,
@@ -283,7 +263,7 @@ describe('debug', () => {
283
263
conn . end ( ) ;
284
264
//wait 100ms to ensure stream has been written
285
265
setTimeout ( ( ) => {
286
- const data = fs . readFileSync ( tmpLogFile , 'utf8' ) ;
266
+ const data = fs . readFileSync ( path . join ( os . tmpdir ( ) , 'combined' + fileIncrement + '.txt' ) , 'utf8' ) ;
287
267
const serverVersion = conn . serverVersion ( ) ;
288
268
const range = [ 7500 , 11000 + ( Conf . baseConfig . ssl ? 800 : 0 ) + setNameAddition ] ;
289
269
assert (
@@ -337,7 +317,7 @@ describe('debug', () => {
337
317
const serverVersion = conn . serverVersion ( ) ;
338
318
if ( isMaxscale ( ) || process . env . srv === 'skysql' || process . env . srv === 'skysql-ha' ) compress = false ;
339
319
const range = compress ? [ 60 , 180 ] : [ 60 , 170 ] ;
340
- const data = fs . readFileSync ( tmpLogFile , 'utf8' ) ;
320
+ const data = fs . readFileSync ( path . join ( os . tmpdir ( ) , 'combined' + fileIncrement + '.txt' ) , 'utf8' ) ;
341
321
assert . isTrue ( data . includes ( 'PING' ) ) ;
342
322
assert . isTrue ( data . includes ( 'QUIT' ) ) ;
343
323
0 commit comments