Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 1e0d9a86
authored
Sep 08, 2017
by
木士羽
Committed by
Sushant
Sep 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(sequelize/query): release connection after all retries (#8247)
1 parent
fdf3e99e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
5 deletions
lib/sequelize.js
test/unit/query.test.js
lib/sequelize.js
View file @
1e0d9a8
...
@@ -528,12 +528,14 @@ class Sequelize {
...
@@ -528,12 +528,14 @@ class Sequelize {
return
options
.
transaction
?
options
.
transaction
.
connection
:
this
.
connectionManager
.
getConnection
(
options
);
return
options
.
transaction
?
options
.
transaction
.
connection
:
this
.
connectionManager
.
getConnection
(
options
);
}).
then
(
connection
=>
{
}).
then
(
connection
=>
{
const
query
=
new
this
.
dialect
.
Query
(
connection
,
this
,
options
);
const
query
=
new
this
.
dialect
.
Query
(
connection
,
this
,
options
);
const
retryOptions
=
Utils
.
_
.
extend
(
this
.
options
.
retry
,
options
.
retry
||
{});
return
retry
(()
=>
query
.
run
(
sql
,
bindParameters
).
finally
(()
=>
{
return
retry
(()
=>
query
.
run
(
sql
,
bindParameters
),
retryOptions
)
if
(
!
options
.
transaction
)
{
.
finally
(()
=>
{
return
this
.
connectionManager
.
releaseConnection
(
connection
);
if
(
!
options
.
transaction
)
{
}
return
this
.
connectionManager
.
releaseConnection
(
connection
);
}),
Utils
.
_
.
extend
(
this
.
options
.
retry
,
options
.
retry
||
{}));
}
});
}).
finally
(()
=>
{
}).
finally
(()
=>
{
if
(
this
.
test
.
_trackRunningQueries
)
{
if
(
this
.
test
.
_trackRunningQueries
)
{
this
.
test
.
_runningQueries
--
;
this
.
test
.
_runningQueries
--
;
...
...
test/unit/query.test.js
0 → 100644
View file @
1e0d9a8
'use strict'
;
const
chai
=
require
(
'chai'
),
sinon
=
require
(
'sinon'
),
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/support'
),
Sequelize
=
Support
.
Sequelize
,
Promise
=
Sequelize
.
Promise
,
current
=
Support
.
sequelize
;
describe
(
'sequelize.query'
,
()
=>
{
it
(
'connection should be released only once when retry fails'
,
()
=>
{
const
getConnectionStub
=
sinon
.
stub
(
current
.
connectionManager
,
'getConnection'
,
()
=>
{
return
Promise
.
resolve
({});
});
const
releaseConnectionStub
=
sinon
.
stub
(
current
.
connectionManager
,
'releaseConnection'
,
()
=>
{
return
Promise
.
resolve
();
});
const
queryStub
=
sinon
.
stub
(
current
.
dialect
.
Query
.
prototype
,
'run'
,
()
=>
{
return
Promise
.
reject
(
new
Error
(
'wrong sql'
));
});
return
current
.
query
(
'THIS IS A WRONG SQL'
,
{
retry
:
{
max
:
2
,
// retry for all errors
match
:
null
}
})
.
catch
(()
=>
{})
.
finally
(()
=>
{
expect
(
releaseConnectionStub
).
have
.
been
.
calledOnce
;
queryStub
.
restore
();
getConnectionStub
.
restore
();
releaseConnectionStub
.
restore
();
});
});
});
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment