mirror of
https://github.com/knex/knex.git
synced 2025-07-16 13:30:42 +00:00

* Normalized and validated driverNames of test db clients and fixed oracle test setup * Fixed failed queries from old query building tests which hadn't been ran in ages * Allow selecting node version which is used to run oracledb docker tests * Improved sql tester error messages * Fixed rest of the oracledb tests * Removed invalid flag from docker-compose * Print mssql logs if initialization fails * Fixed syntax error + final tests * Added restart of failure for mssql DB initialization to try again if server was not ready * Printout always mssql logs after container is started * Fixed wait time printing after trying to connect * Use npm run oracledb:test for testing oracle in travis
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
const PAUSE_BETWEEN_CONNECTIONS = 2000;
|
|
const CONNECTION_ATTEMPTS = 3 * 60 * 1000 / PAUSE_BETWEEN_CONNECTIONS; // roughly 3 minutes
|
|
|
|
const Connection = require('tedious').Connection;
|
|
|
|
const config = {
|
|
userName: "sa",
|
|
password: "S0meVeryHardPassword",
|
|
server: "localhost",
|
|
options: {
|
|
database: "knex_test",
|
|
}
|
|
};
|
|
|
|
let didConnect = false;
|
|
let tryCount = 0;
|
|
|
|
function tryToConnect() {
|
|
tryCount++;
|
|
if (tryCount > CONNECTION_ATTEMPTS) {
|
|
console.log("Giving up... it fails if it fails");
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log("Connecting... to mssql");
|
|
|
|
const connection = new Connection(config);
|
|
|
|
connection.on('end', () => {
|
|
if (!didConnect) {
|
|
console.log(`Couldnt connnect yet... try again in ${PAUSE_BETWEEN_CONNECTIONS}ms...`);
|
|
setTimeout(tryToConnect, PAUSE_BETWEEN_CONNECTIONS);
|
|
}
|
|
});
|
|
|
|
connection.on('error', () => {
|
|
// prevent leaking errors.. driver seems to sometimes emit error event,
|
|
// sometimes connect event with error
|
|
// and some times just closes connection without error / connect events
|
|
// (debug event says that socket was ended and thats it...)
|
|
});
|
|
|
|
connection.on('connect', (err) => {
|
|
if (!err) {
|
|
console.log("Connecting mssql server was a great success!");
|
|
didConnect = true;
|
|
} else {
|
|
console.log("Error was passed to connect event.");
|
|
}
|
|
connection.close();
|
|
});
|
|
}
|
|
|
|
tryToConnect();
|