Skip to content

Commit

Permalink
test(client): port too many instances (#13927)
Browse files Browse the repository at this point in the history
* test: port too many instances

* refactor: use jest.resetModules

* delete: old test
  • Loading branch information
danstarns committed Jun 23, 2022
1 parent 8e9f510 commit 99a7d8a
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 66 deletions.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

@@ -0,0 +1,24 @@
import { defineMatrix } from '../_utils/defineMatrix'

export default defineMatrix(() => [
[
{
provider: 'sqlite',
},
{
provider: 'postgresql',
},
{
provider: 'mysql',
},
{
provider: 'sqlserver',
},
{
provider: 'cockroachdb',
},
{
provider: 'mongodb',
},
],
])
@@ -0,0 +1,19 @@
import { idForProvider } from '../../_utils/idForProvider'
import testMatrix from '../_matrix'

export default testMatrix.setupSchema(({ provider }) => {
return /* Prisma */ `
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "${provider}"
url = env("DATABASE_URI_${provider}")
}
model User {
id ${idForProvider(provider)}
}
`
})
@@ -0,0 +1,36 @@
import testMatrix from './_matrix'

// @ts-ignore this is just for type checks
declare let PrismaClient: typeof import('@prisma/client').PrismaClient

testMatrix.setupTestSuite(() => {
const oldConsoleWarn = console.warn
const warnings: any[] = []
const clients: any[] = []

beforeAll(() => {
jest.resetModules()

console.warn = (args) => {
warnings.push(args)
}
})

afterAll(() => {
console.warn = oldConsoleWarn
})

test('should console warn when spawning too many instances of PrismaClient', async () => {
for (let i = 0; i < 15; i++) {
const client = new PrismaClient()
await client.$connect()
clients.push(client)
}

for (const client of clients) {
client.$disconnect()
}

expect(warnings.join('')).toContain('There are already 10 instances of Prisma Client actively running')
})
})

0 comments on commit 99a7d8a

Please sign in to comment.