-
Notifications
You must be signed in to change notification settings - Fork 2.5k
switch user back to pool default on connection release #1088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
seangarner
wants to merge
4
commits into
mysqljs:master
from
seangarner:no-disconnect-on-changeUser-return
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
589a833
switch user back to pool default on connection release
seangarner 1fcba72
use purgeConnection instead of destroy on restoreUser error
seangarner 8989512
test connection is running user it says it is
seangarner 8a94f9b
fire changeUser when returned connection has different charset than pool
seangarner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,19 +9,29 @@ var pool = common.createPool({ | |
var closed = 0; | ||
var server = common.createFakeServer(); | ||
var thread = 0; | ||
var connections = 0; | ||
|
||
server.listen(common.fakeServerPort, function(err) { | ||
assert.ifError(err); | ||
|
||
pool.on('connection', function(conn) { | ||
connections++; | ||
}); | ||
|
||
var conn0; | ||
var threadId; | ||
pool.getConnection(function(err, conn) { | ||
assert.ifError(err); | ||
assert.ok(conn.threadId === 1 || conn.threadId === 2); | ||
conn.query('SELECT CURRENT_USER()', function (err, rows) { | ||
assert.ifError(err); | ||
assert.strictEqual(rows[0]['CURRENT_USER()'].indexOf('user_1'), 0); | ||
}); | ||
conn0 = conn; | ||
threadId = conn.threadId; | ||
}); | ||
|
||
|
||
pool.getConnection(function(err, conn) { | ||
assert.ifError(err); | ||
assert.ok(conn.threadId === 1 || conn.threadId === 2); | ||
|
@@ -31,24 +41,39 @@ server.listen(common.fakeServerPort, function(err) { | |
conn.changeUser({user: 'user_2'}, function(err) { | ||
assert.ifError(err); | ||
assert.strictEqual(conn.threadId, threadId); | ||
conn.query('SELECT CURRENT_USER()', function (err, rows) { | ||
assert.ifError(err); | ||
assert.strictEqual(rows[0]['CURRENT_USER()'].indexOf('user_2'), 0); | ||
}); | ||
conn.release(); | ||
conn0.release(); | ||
}); | ||
}); | ||
|
||
pool.getConnection(function(err, conn1) { | ||
assert.ifError(err); | ||
assert.strictEqual(conn1.threadId, 3); | ||
assert.ok(conn1.threadId === 1 || conn1.threadId === 2); | ||
assert.strictEqual(conn1.config.user, 'user_1'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test needs to run the query There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 8989512 |
||
conn1.query('SELECT CURRENT_USER()', function (err, rows) { | ||
assert.ifError(err); | ||
assert.strictEqual(rows[0]['CURRENT_USER()'].indexOf('user_1'), 0); | ||
}); | ||
|
||
pool.getConnection(function(err, conn2) { | ||
assert.ifError(err); | ||
assert.strictEqual(conn2.threadId, threadId); | ||
conn1.release(); | ||
conn2.release(); | ||
assert.ok(conn2.threadId === 1 || conn2.threadId === 2); | ||
assert.strictEqual(conn1.config.user, 'user_1'); | ||
conn2.query('SELECT CURRENT_USER()', function (err, rows) { | ||
assert.ifError(err); | ||
assert.strictEqual(rows[0]['CURRENT_USER()'].indexOf('user_1'), 0); | ||
conn1.release(); | ||
conn2.release(); | ||
}); | ||
|
||
pool.end(function(err) { | ||
assert.ifError(err); | ||
assert.strictEqual(closed, 3); | ||
assert.strictEqual(connections, 3); | ||
assert.strictEqual(closed, 2); | ||
server.destroy(); | ||
}); | ||
}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no such thing as
config.charset
, onlyconfig.charsetNumber
.