Skip to content

Commit 2cd902c

Browse files
committed
Complete tests, refactoring
1 parent b369e1e commit 2cd902c

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

plugin.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ function transactScope (pool, fn, cb) {
88
if (err) return cb(err)
99

1010
const commit = (err, res) => {
11-
if (err) {
12-
return conn.close(function () {
13-
return cb(err)
14-
})
15-
}
11+
if (err) return conn.close(() => cb(err))
1612

1713
conn.commit(function (err) {
1814
conn.close(function () {

test/plugin.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,30 @@ test('transact with promise + invalid connection pool', (t) => {
307307
})
308308
})
309309
})
310+
311+
test('transact commit should error if connection drops', (t) => {
312+
t.plan(6)
313+
314+
const fastify = Fastify()
315+
fastify.register(plugin, { pool: poolOptions, objectOutput: true })
316+
317+
fastify.ready(err => {
318+
t.error(err)
319+
t.ok(fastify.oracle.pool)
320+
321+
fastify.oracle.transact((conn, commit) => {
322+
conn.execute('SELECT * FROM DUAL', function (err, result) {
323+
conn.close(() => {
324+
commit(err, result)
325+
})
326+
})
327+
}, function (err, res) {
328+
t.is(res, undefined)
329+
t.is(err.message, 'NJS-003: invalid connection')
330+
fastify.close(err => {
331+
t.error(err)
332+
t.is(fastify.oracle.pool.status, fastify.oracle.db.POOL_STATUS_CLOSED)
333+
})
334+
})
335+
})
336+
})

0 commit comments

Comments
 (0)