Skip to content

Commit 5388644

Browse files
dhensbyCopilot
andcommitted
fix: improve test robustness and docs for per-request timeout
- Add success handlers to all per-request timeout integration tests so they fail fast instead of hanging if timeout is not applied - Remove accidental .releaserc change from this branch - Clarify README docs for using options with the global pool Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 074156b commit 5388644

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

.releaserc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ plugins:
44
- '@semantic-release/release-notes-generator'
55
- '@semantic-release/npm'
66
- '@semantic-release/github'
7-
- '@semantic-release/git'

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,8 @@ The optional `options` argument allows per-request configuration overrides:
870870
const request = new sql.Request(pool, { requestTimeout: 60000 })
871871
```
872872

873+
**Note:** When using the global pool, you must still pass `undefined` as the first argument to use options: `new sql.Request(undefined, { requestTimeout: 60000 })`.
874+
873875
### Events
874876

875877
- **recordset(columns)** - Dispatched when metadata for new recordset are parsed.

test/common/tests.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,10 @@ module.exports = (sql, driver) => {
12051205

12061206
new sql.ConnectionPool(config).connect().then(conn => {
12071207
const req = new sql.Request(conn, { requestTimeout: 1000 })
1208-
req.query('waitfor delay \'00:00:05\';select 1').catch(err => {
1208+
req.query('waitfor delay \'00:00:05\';select 1').then(() => {
1209+
conn.close()
1210+
done(new Error('Expected request to timeout'))
1211+
}).catch(err => {
12091212
assert.ok((message ? (message.exec(err.message) != null) : (err instanceof sql.RequestError)))
12101213

12111214
conn.close()
@@ -1246,7 +1249,12 @@ module.exports = (sql, driver) => {
12461249
const tx = new sql.Transaction(conn, { requestTimeout: 1000 })
12471250
tx.begin().then(() => {
12481251
const req = tx.request()
1249-
req.query('waitfor delay \'00:00:05\';select 1').catch(err => {
1252+
req.query('waitfor delay \'00:00:05\';select 1').then(() => {
1253+
tx.rollback().catch(() => {}).then(() => {
1254+
conn.close()
1255+
done(new Error('Expected request to timeout'))
1256+
})
1257+
}).catch(err => {
12501258
assert.ok((message ? (message.exec(err.message) != null) : (err instanceof sql.RequestError)))
12511259

12521260
tx.rollback().then(() => {
@@ -1271,7 +1279,10 @@ module.exports = (sql, driver) => {
12711279

12721280
new sql.ConnectionPool(config).connect().then(conn => {
12731281
const req = new sql.Request(conn, { requestTimeout: 1000 })
1274-
req.execute('__testDelay').catch(err => {
1282+
req.execute('__testDelay').then(() => {
1283+
conn.close()
1284+
done(new Error('Expected request to timeout'))
1285+
}).catch(err => {
12751286
assert.ok((message ? (message.exec(err.message) != null) : (err instanceof sql.RequestError)))
12761287

12771288
conn.close()
@@ -1288,7 +1299,12 @@ module.exports = (sql, driver) => {
12881299
new sql.ConnectionPool(config).connect().then(conn => {
12891300
const ps = new sql.PreparedStatement(conn, { requestTimeout: 1000 })
12901301
ps.prepare('waitfor delay \'00:00:05\';select 1').then(() => {
1291-
ps.execute().catch(err => {
1302+
ps.execute().then(() => {
1303+
ps.unprepare().catch(() => {}).then(() => {
1304+
conn.close()
1305+
done(new Error('Expected request to timeout'))
1306+
})
1307+
}).catch(err => {
12921308
assert.ok((message ? (message.exec(err.message) != null) : (err instanceof sql.RequestError)))
12931309

12941310
ps.unprepare().then(() => {

0 commit comments

Comments
 (0)