Created
January 12, 2020 11:32
-
-
Save vitaly-t/41e9a9bd7e0171587bc602b8f53af5b7 to your computer and use it in GitHub Desktop.
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
const header = require('./db/header'); | |
const promise = header.defPromise; | |
const options = { | |
promiseLib: promise, | |
noWarnings: true | |
}; | |
const dbHeader = header(options); | |
const pgp = dbHeader.pgp; | |
const db = dbHeader.db; | |
const IDLE_TIMEOUT_MS = 100; | |
const SLEEP_TIME_SEC = 0.2; | |
describe('idle-in-transaction-session-timeout', () => { | |
describe('recovery', () => { | |
it('should get a new connection after the timeout', async (done) => { | |
await db.any('SET idle_in_transaction_session_timeout TO $1;', IDLE_TIMEOUT_MS); | |
try { | |
await db.tx(async t => { | |
await new Promise(resolve => setTimeout(resolve, SLEEP_TIME_SEC * 1000)); | |
return t.one('SELECT $1 AS sleep_sec', SLEEP_TIME_SEC); | |
}); | |
done('dbIdle must throw an exception'); | |
} catch (e) { | |
expect(e.message).toContain('is not queryable'); | |
} | |
try { | |
await db.one('SELECT 1 + 1 AS res'); | |
} catch (e) { | |
done('query after session timeout failed! ' + e.message); | |
} | |
done(); | |
}); | |
}); | |
}); | |
if (jasmine.Runner) { | |
const _finishCallback = jasmine.Runner.prototype.finishCallback; | |
jasmine.Runner.prototype.finishCallback = function () { | |
// Run the old finishCallback: | |
_finishCallback.bind(this)(); | |
pgp.end(); // closing pg database application pool; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment