@@ -6,8 +6,10 @@ const async = require('async')
6
6
module . exports = exports = setup
7
7
exports . pool = setupPool
8
8
const params = exports . params = {
9
- mysql_host : process . env . NR_NODE_TEST_MYSQL_HOST || 'localhost' ,
10
- mysql_port : process . env . NR_NODE_TEST_MYSQL_PORT || 3306
9
+ host : process . env . NR_NODE_TEST_MYSQL_HOST || 'localhost' ,
10
+ port : process . env . NR_NODE_TEST_MYSQL_PORT || 3306 ,
11
+ user : 'test_user' ,
12
+ database : 'agent_integration_' + Math . floor ( Math . random ( ) * 1000 )
11
13
}
12
14
13
15
function setup ( mysql , cb ) {
@@ -22,9 +24,9 @@ function setup(mysql, cb) {
22
24
} )
23
25
24
26
async . eachSeries ( [
25
- ' CREATE USER test_user' ,
26
- ' GRANT ALL ON *.* TO `test_user`' ,
27
- ' CREATE DATABASE IF NOT EXISTS `agent_integration`'
27
+ ` CREATE USER ${ params . user } ` ,
28
+ ` GRANT ALL ON *.* TO ${ params . user } ` ,
29
+ ` CREATE DATABASE IF NOT EXISTS ${ params . database } `
28
30
] , ( sql , cb ) => {
29
31
client . query ( sql , ( err ) => {
30
32
// Travis uses MySQL 5.4 which does not support `IF NOT EXISTS` for
@@ -45,12 +47,7 @@ function setup(mysql, cb) {
45
47
46
48
// 2. Create the table and data as test user.
47
49
( cb ) => {
48
- var client = mysql . createConnection ( {
49
- host : params . mysql_host ,
50
- port : params . mysql_port ,
51
- user : 'test_user' ,
52
- database : 'agent_integration'
53
- } )
50
+ var client = mysql . createConnection ( params )
54
51
55
52
async . eachSeries ( [
56
53
[
@@ -83,12 +80,7 @@ function setupPool(mysql, logger) {
83
80
log : ( message ) => logger . info ( message ) ,
84
81
85
82
create : ( callback ) => {
86
- var client = mysql . createConnection ( {
87
- user : 'test_user' ,
88
- database : 'agent_integration' ,
89
- host : params . mysql_host ,
90
- port : params . mysql_port
91
- } )
83
+ var client = mysql . createConnection ( params )
92
84
93
85
client . on ( 'error' , ( err ) => {
94
86
logger . error ( 'MySQL connection errored out, destroying connection' )
0 commit comments