Skip to content

Commit

Permalink
#142 - Fix ReferenceError in instance lookup error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
patriksimek committed Apr 1, 2014
1 parent ecb19d8 commit 36cb355
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"url": "https://raw.github.com/pekim/tedious/master/LICENSE"
}
],
"version": "0.2.1",
"version": "0.2.2",
"main": "./lib/tedious.js",
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions src/connection.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ class Connection extends EventEmitter
if (@config.options.port)
@connectOnPort(@config.options.port)
else
instanceLookup(@config.server, @config.options.instanceName, (err, port) =>
if err
instanceLookup(@config.server, @config.options.instanceName, (message, port) =>
if message
@emit('connect', ConnectionError(message, 'EINSTLOOKUP'))
else
@connectOnPort(port)
Expand All @@ -378,7 +378,7 @@ class Connection extends EventEmitter
)

closeConnection: ->
@socket.destroy()
@socket?.destroy()

createConnectTimer: ->
@connectTimer = setTimeout(@connectTimeout, @config.options.connectTimeout)
Expand Down
33 changes: 33 additions & 0 deletions test/integration/connection-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,39 @@ exports.connectByInstanceName = (test) ->
#console.log(text)
)

exports.connectByInvalidInstanceName = (test) ->
if !getInstanceName()
# Config says don't do this test (probably because SQL Server Browser is not available).
console.log('Skipping connectByInvalidInstanceName test')
test.done()
return

test.expect(1)

config = getConfig()
delete config.options.port
config.options.instanceName = "#{getInstanceName()}X"

connection = new Connection(config)

connection.on('connect', (err) ->
test.ok(err)

connection.close()
)

connection.on('end', (info) ->
test.done()
)

connection.on('infoMessage', (info) ->
#console.log("#{info.number} : #{info.message}")
)

connection.on('debug', (text) ->
#console.log(text)
)


exports.encrypt = (test) ->
test.expect(5)
Expand Down

0 comments on commit 36cb355

Please sign in to comment.