Skip to content
Permalink
Browse files
[misc] change pool implementation to permit node 6 compatibility (rem…
…oval of async await)
  • Loading branch information
rusher committed Jul 17, 2018
1 parent 92cb4be commit 924f958
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 153 deletions.
@@ -9,10 +9,10 @@
"markdown"
],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
"ecmaVersion": 6
},
"env": {
"node": true
"node": true,
"es6": true
}
}
@@ -41,6 +41,8 @@ matrix:
include:
- node_js: "node"
env: DB=build
- node_js: "6"
env: DB=mariadb:10.2 SKIP_LEAK=1
- node_js: "8"
env: DB=mariadb:10.2
- node_js: "node"
@@ -13,7 +13,7 @@

**Non-blocking MariaDB and MySQL client for Node.js.**

MariaDB and MySQL client, 100% JavaScript, compatible with Node.js 7.6+, with the Promise API.
MariaDB and MySQL client, 100% JavaScript, compatible with Node.js 6+, with the Promise API.

## Why a New Client?

@@ -11,6 +11,11 @@ environment:
TEST_HOST: mariadb.example.com
matrix:

- DB: '10.2.16'
MEM: "21"
nodejs_version: "6"
SKIP_LEAK: "1"

- DB: '10.2.16'
MEM: "21"
nodejs_version: "8"
@@ -46,26 +46,29 @@ module.exports.benchFct = function(conn, deferred) {
});
};

module.exports.initFct = async function(conn) {
try {
await conn.query("DROP TABLE IF EXISTS testn.perfTestText");
await conn.query("INSTALL SONAME 'ha_blackhole'");
await conn.query(sqlTable + " ENGINE = BLACKHOLE COLLATE='utf8mb4_unicode_ci'");
} catch (e) {
try {
await conn.query("DROP TABLE IF EXISTS testn.perfTestText");
await conn.query(sqlTable + " COLLATE='utf8mb4_unicode_ci'");
} catch (e) {
module.exports.initFct = function(conn) {
return Promise.all([
conn.query("DROP TABLE IF EXISTS testn.perfTestText"),
conn.query("INSTALL SONAME 'ha_blackhole'"),
conn.query(sqlTable + " ENGINE = BLACKHOLE COLLATE='utf8mb4_unicode_ci'")
])
.catch(err => {
return Promise.all([
conn.query("DROP TABLE IF EXISTS testn.perfTestText"),
conn.query(sqlTable + " COLLATE='utf8mb4_unicode_ci'")
])
})
.catch(e => {
console.log(e);
throw e;
}
}
});

};

module.exports.onComplete = async function(conn) {
try {
await conn.query("TRUNCATE TABLE testn.perfTestText");
} catch (e) {
//eat
}
module.exports.onComplete = function(conn) {
conn.query("TRUNCATE TABLE testn.perfTestText")
.catch(e => {
console.log(e);
throw e;
});
};
@@ -41,26 +41,30 @@ module.exports.benchFct = function(conn, deferred) {
}
};

module.exports.initFct = async function(conn) {
try {
await conn.query("DROP TABLE IF EXISTS testn.perfTestTextPipe");
await conn.query("INSTALL SONAME 'ha_blackhole'");
await conn.query(sqlTable + " ENGINE = BLACKHOLE COLLATE='utf8mb4_unicode_ci'");
} catch (e) {
try {
await conn.query("DROP TABLE IF EXISTS testn.perfTestTextPipe");
await conn.query(sqlTable + " COLLATE='utf8mb4_unicode_ci'");
} catch (e) {

module.exports.initFct = function(conn) {
return Promise.all([
conn.query("DROP TABLE IF EXISTS testn.perfTestTextPipe"),
conn.query("INSTALL SONAME 'ha_blackhole'"),
conn.query(sqlTable + " ENGINE = BLACKHOLE COLLATE='utf8mb4_unicode_ci'")
])
.catch(err => {
return Promise.all([
conn.query("DROP TABLE IF EXISTS testn.perfTestTextPipe"),
conn.query(sqlTable + " COLLATE='utf8mb4_unicode_ci'")
])
})
.catch(e => {
console.log(e);
throw e;
}
}
});

};

module.exports.onComplete = async function(conn) {
try {
await conn.query("TRUNCATE TABLE testn.perfTestTextPipe");
} catch (e) {
//eat
}
module.exports.onComplete = function(conn) {
conn.query("TRUNCATE TABLE testn.perfTestTextPipe")
.catch(e => {
console.log(e);
throw e;
});
};
@@ -221,6 +221,7 @@ function Bench() {
},
// called when the suite completes running
onComplete: function() {
console.log("completed");
bench.end(bench);
}
});
@@ -240,7 +241,7 @@ Bench.prototype.end = function(bench) {
bench.displayReport();
};

Bench.prototype.endConnection = async function(conn) {
Bench.prototype.endConnection = function(conn) {
try {
//using destroy, because MySQL driver fail when using end() for windows named pipe
conn.drv.destroy();
@@ -249,12 +250,11 @@ Bench.prototype.endConnection = async function(conn) {
console.log(err);
}
if (conn.pool) {
try {
await conn.pool.end();
} catch (err) {
console.log("ending error for pool '" + conn.desc + "'");
console.log(err);
}
conn.pool.end()
.catch(err => {
console.log("ending error for pool '" + conn.desc + "'");
console.log(err);
});
}
};

@@ -411,6 +411,20 @@ const pingAll = function(conns) {
let keys = Object.keys(conns);
for (let k = 0; k < keys.length; ++k) {
conns[keys[k]].drv.ping();
if (conns[keys[k]].pool) {
for (let i = 0; i < 10; i++) {
conns[keys[k]].pool.getConnection()
.then(conn => {
conn.ping()
.then(() => {
conn.release();
})
.catch(err => {
conn.release();
})
})
}
}
}
};

0 comments on commit 924f958

Please sign in to comment.