From 25cd61e3b9a3451e68e9f6ea267ac8497ad52d51 Mon Sep 17 00:00:00 2001 From: Ben Page Date: Mon, 8 Aug 2016 16:03:10 -0500 Subject: [PATCH] added appveyor.yml --- appveyor.yml | 28 ++++ enable-sql-server-tcp-ip.ps1 | 25 ++++ test/test.js | 254 +++++++++++++++++++---------------- 3 files changed, 191 insertions(+), 116 deletions(-) create mode 100644 appveyor.yml create mode 100644 enable-sql-server-tcp-ip.ps1 diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..8cecdbd --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,28 @@ +version: "{build}" + +services: mssql2014 + +environment: + matrix: + - nodejs_version: "0.10" + - nodejs_version: "0.12" + - nodejs_version: "4" + - nodejs_version: "5" + - nodejs_version: "6" + +branches: + only: + - master + +install: + - ps: Install-Product node $env:nodejs_version + - cmd: npm install + +cache: node_modules +build: off + +before_test: + - ps: Start-Process enable-sql-server-tcp-ip.ps1 + +test_script: + - cmd: npm test diff --git a/enable-sql-server-tcp-ip.ps1 b/enable-sql-server-tcp-ip.ps1 new file mode 100644 index 0000000..c606386 --- /dev/null +++ b/enable-sql-server-tcp-ip.ps1 @@ -0,0 +1,25 @@ +[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null +[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement") | Out-Null + +$instanceName = 'sql2014' +$computerName = $env:COMPUTERNAME +$smo = 'Microsoft.SqlServer.Management.Smo.' +$wmi = New-Object ($smo + 'Wmi.ManagedComputer') + +# For the named instance, on the current computer, for the TCP protocol, +# loop through all the IPs and configure them to use the standard port +# of 1433. +$uri = "ManagedComputer[@Name='$computerName']/ ServerInstance[@Name='$instanceName']/ServerProtocol[@Name='Tcp']" +$Tcp = $wmi.GetSmoObject($uri) +ForEach ($ipAddress in $Tcp.IPAddresses) +{ + $ipAddress.IPAddressProperties["TcpDynamicPorts"].Value = "" + $ipAddress.IPAddressProperties["TcpPort"].Value = "1433" +} +$Tcp.IsEnabled = $true +$Tcp.Alter() + +# Start services +Set-Service SQLBrowser -StartupType Manual +Start-Service SQLBrowser +Restart-Service "MSSQL`$$instanceName" \ No newline at end of file diff --git a/test/test.js b/test/test.js index e8c3f1f..252d16e 100644 --- a/test/test.js +++ b/test/test.js @@ -4,15 +4,35 @@ var Request = require('tedious').Request; var ConnectionPool = require('../lib/connection-pool'); var Connection = require('tedious').Connection; -var connectionConfig = { - userName: 'test', - password: 'test', - server: 'dev1', - options: { - appName: 'pool-test', - database: 'test' - } -}; +var connectionConfig, timeout; + +if (process.env.APPVEYOR) { + timeout = 30000; + connectionConfig = { + server: 'localhost', + userName: 'sa', + password: 'Password12!', + options: { + appName: 'pool-test', + database: 'master', + requestTimeout: 25000, + cryptoCredentialsDetails: { + ciphers: 'RC4-MD5' + } + } + }; +} else { + timeout = 10000; + connectionConfig = { + userName: 'test', + password: 'test', + server: 'dev1', + options: { + appName: 'pool-test', + database: 'test' + } + }; +} /* create a db user with the correct permissions: CREATE DATABASE test @@ -56,7 +76,7 @@ describe('Name Collision', function () { describe('ConnectionPool', function () { it('min', function (done) { - this.timeout(10000); + this.timeout(timeout); var poolConfig = {min: 2}; var pool = new ConnectionPool(poolConfig, connectionConfig); @@ -68,7 +88,7 @@ describe('ConnectionPool', function () { }); it('min=0', function (done) { - this.timeout(10000); + this.timeout(timeout); var poolConfig = {min: 0, idleTimeout: 10}; var pool = new ConnectionPool(poolConfig, connectionConfig); @@ -100,7 +120,7 @@ describe('ConnectionPool', function () { }); it('max', function (done) { - this.timeout(10000); + this.timeout(timeout); var poolConfig = {min: 2, max: 5}; var pool = new ConnectionPool(poolConfig, connectionConfig); @@ -139,7 +159,7 @@ describe('ConnectionPool', function () { }); it('min<=max, min specified > max specified', function (done) { - this.timeout(10000); + this.timeout(timeout); var poolConfig = { min: 5, max: 1, idleTimeout: 10}; var pool = new ConnectionPool(poolConfig, connectionConfig); @@ -171,7 +191,7 @@ describe('ConnectionPool', function () { }); it('min<=max, no min specified', function (done) { - this.timeout(10000); + this.timeout(timeout); var poolConfig = {max: 1, idleTimeout: 10}; var pool = new ConnectionPool(poolConfig, connectionConfig); @@ -203,7 +223,7 @@ describe('ConnectionPool', function () { }); it('pool error event', function (done) { - this.timeout(10000); + this.timeout(timeout); var poolConfig = {min: 3}; var pool = new ConnectionPool(poolConfig, {}); @@ -216,7 +236,7 @@ describe('ConnectionPool', function () { }); it('connection retry', function (done) { - this.timeout(10000); + this.timeout(timeout); var poolConfig = {min: 1, max: 5, retryDelay: 5}; var pool = new ConnectionPool(poolConfig, {}); @@ -241,7 +261,7 @@ describe('ConnectionPool', function () { }); it('acquire timeout', function (done) { - this.timeout(10000); + this.timeout(timeout); var poolConfig = {min: 1, max: 1, acquireTimeout: 2000}; var pool = new ConnectionPool(poolConfig, connectionConfig); @@ -259,7 +279,7 @@ describe('ConnectionPool', function () { }); it('idle timeout', function (done) { - this.timeout(10000); + this.timeout(timeout); var poolConfig = {min: 1, max: 5, idleTimeout: 100}; var pool = new ConnectionPool(poolConfig, connectionConfig); @@ -283,7 +303,7 @@ describe('ConnectionPool', function () { }); it('connection error handling', function (done) { - this.timeout(10000); + this.timeout(timeout); var poolConfig = {min: 1, max: 5}; var pool = new ConnectionPool(poolConfig, connectionConfig); @@ -326,7 +346,7 @@ describe('ConnectionPool', function () { }); it('release(), reset()', function (done) { - this.timeout(10000); + this.timeout(timeout); var poolConfig = {max: 1}; var pool = new ConnectionPool(poolConfig, connectionConfig); @@ -363,7 +383,7 @@ describe('ConnectionPool', function () { }); it('drain', function (done) { - this.timeout(10000); + this.timeout(timeout); var poolConfig = {min: 3}; var pool = new ConnectionPool(poolConfig, connectionConfig); @@ -377,115 +397,117 @@ describe('ConnectionPool', function () { }); }); -describe('Load Test', function() { - var statistics = require('simple-statistics'); - - it('Memory Leak Detection - Connection Error', function(done) { - this.timeout(60000); - if (!global.gc) - throw new Error('must run nodejs with --expose-gc'); - var count = 0; - var mem = []; - var groupCount = 20; - var poolSize = 1000; - var max = poolSize * groupCount; +if (!process.env.APPVEYOR) { + describe('Load Test', function () { + var statistics = require('simple-statistics'); - var pool = new ConnectionPool({ max: poolSize, min: poolSize, retryDelay: 1}, { - userName: 'testLogin', - password: 'wrongPassword', - server: 'localhost' + it('Memory Leak Detection - Connection Error', function (done) { + this.timeout(60000); + if (!global.gc) + throw new Error('must run nodejs with --expose-gc'); + var count = 0; + var mem = []; + var groupCount = 20; + var poolSize = 1000; + var max = poolSize * groupCount; + + var pool = new ConnectionPool({max: poolSize, min: poolSize, retryDelay: 1}, { + userName: 'testLogin', + password: 'wrongPassword', + server: 'localhost' + }); + + pool.on('error', function () { + if ((++count % poolSize) !== 0) + return; + + global.gc(); + + var heapUsedKB = Math.round(process.memoryUsage().heapUsed / 1024); + mem.push([count, heapUsedKB]); + // console.log(count + ': ' + heapUsedKB + 'KB'); + + if (count === max) { + var data = statistics.linearRegression(mem); + //console.log(data.m); + if (data.m >= 0.025) + done(new Error('Memory leak detected.')); + else + done(); + + pool.drain(); + } + }); }); - pool.on('error', function() { - if ((++count % poolSize) !== 0) - return; + it('Memory Leak Detection - acquire() and Request', function (done) { + this.timeout(60000); + if (!global.gc) + throw new Error('must run nodejs with --expose-gc'); - global.gc(); + var poolConfig = {min: 67, max: 123}; + var pool = new ConnectionPool(poolConfig, { + userName: 'test', + password: 'test', + server: 'dev1' + }); - var heapUsedKB = Math.round(process.memoryUsage().heapUsed / 1024); - mem.push([count, heapUsedKB]); - // console.log(count + ': ' + heapUsedKB + 'KB'); + var clients = 1000; + var connections = 100; + var max = clients * connections; + var mem = []; - if (count === max) { - var data = statistics.linearRegression(mem); - //console.log(data.m); - if (data.m >= 0.025) - done(new Error('Memory leak detected.')); - else - done(); - + for (var i = 0; i < clients; i++) + createClient(); + + var count = 0; + + function end(err) { + done(err); pool.drain(); } - }); - }); - - it('Memory Leak Detection - acquire() and Request', function(done) { - this.timeout(60000); - if (!global.gc) - throw new Error('must run nodejs with --expose-gc'); - - var poolConfig = {min: 67, max: 123}; - var pool = new ConnectionPool(poolConfig, { - userName: 'test', - password: 'test', - server: 'dev1' - }); - - var clients = 1000; - var connections = 100; - var max = clients * connections; - var mem = []; - - for (var i = 0; i < clients; i++) - createClient(); - - var count = 0; - - function end(err) { - done(err); - pool.drain(); - } - - function createClient() { - var clientCount = 0; - - function createRequest() { - pool.acquire(function(err, connection) { - if (err) - return end(err); + + function createClient() { + var clientCount = 0; - var request = new Request('select 42', function (err) { + function createRequest() { + pool.acquire(function (err, connection) { if (err) return end(err); - - connection.release(); - - if (++clientCount < connections) - createRequest(); - - if ((++count % 1000) === 0) { - global.gc(); - if (count === max) { - var data = statistics.linearRegression(mem); - //console.log(data.m); - if (data.m >= 0.025) - end(new Error('Memory leak detected.')); - else - end(); - } else { - var heapUsedKB = Math.round(process.memoryUsage().heapUsed / 1024); - mem.push([count, heapUsedKB]); - // console.log(count + ': ' + heapUsedKB + 'KB'); + var request = new Request('select 42', function (err) { + if (err) + return end(err); + + connection.release(); + + if (++clientCount < connections) + createRequest(); + + if ((++count % 1000) === 0) { + global.gc(); + + if (count === max) { + var data = statistics.linearRegression(mem); + //console.log(data.m); + if (data.m >= 0.025) + end(new Error('Memory leak not detected.')); + else + end(); + } else { + var heapUsedKB = Math.round(process.memoryUsage().heapUsed / 1024); + mem.push([count, heapUsedKB]); + // console.log(count + ': ' + heapUsedKB + 'KB'); + } } - } + }); + + connection.execSql(request); }); + } - connection.execSql(request); - }); + createRequest(); } - - createRequest(); - } + }); }); -}); +} \ No newline at end of file