-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle connection errors @
MssqlDriver
. (#1042)
- Loading branch information
1 parent
87f365e
commit fb5bf4d
Showing
3 changed files
with
88 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Kysely, MssqlDialect, sql } from '../../..' | ||
import { DIALECTS, DIALECT_CONFIGS, Database, expect } from './test-setup' | ||
import * as tarn from 'tarn' | ||
import * as tedious from 'tedious' | ||
|
||
const dialect = 'mssql' | ||
|
||
if (DIALECTS.includes(dialect)) { | ||
describe(`${dialect}: disconnects`, () => { | ||
let connection: tedious.Connection | ||
let connectionFactoryTimesCalled = 0 | ||
let db: Kysely<Database> | ||
|
||
before(async () => { | ||
db = new Kysely({ | ||
dialect: new MssqlDialect({ | ||
tarn: { | ||
...tarn, | ||
options: { | ||
min: 0, | ||
max: 1, | ||
}, | ||
}, | ||
tedious: { | ||
...tedious, | ||
connectionFactory: () => { | ||
connectionFactoryTimesCalled++ | ||
|
||
return (connection = new tedious.Connection( | ||
DIALECT_CONFIGS[dialect], | ||
)) | ||
}, | ||
}, | ||
}), | ||
}) | ||
}) | ||
|
||
after(async () => { | ||
await db.destroy() | ||
}) | ||
|
||
it('should be disconnection tolerant', async () => { | ||
await sql`select 1`.execute(db) | ||
expect(connectionFactoryTimesCalled).to.equal(1) | ||
|
||
connection.socketError(new Error('moshe')) | ||
|
||
await sql`select 1`.execute(db) | ||
expect(connectionFactoryTimesCalled).to.equal(2) | ||
}) | ||
}) | ||
} |