Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(client): port too many instances (#13927)
* test: port too many instances * refactor: use jest.resetModules * delete: old test
- Loading branch information
Showing
7 changed files
with
79 additions
and
66 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
...es/client/src/__tests__/integration/errors/too-many-instances-of-prisma-client/.gitignore
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-56 KB
packages/client/src/__tests__/integration/errors/too-many-instances-of-prisma-client/dev.db
Binary file not shown.
36 changes: 0 additions & 36 deletions
36
...client/src/__tests__/integration/errors/too-many-instances-of-prisma-client/schema.prisma
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
packages/client/src/__tests__/integration/errors/too-many-instances-of-prisma-client/test.ts
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
packages/client/tests/functional/too-many-instances-of-prisma-client/_matrix.ts
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,24 @@ | ||
import { defineMatrix } from '../_utils/defineMatrix' | ||
|
||
export default defineMatrix(() => [ | ||
[ | ||
{ | ||
provider: 'sqlite', | ||
}, | ||
{ | ||
provider: 'postgresql', | ||
}, | ||
{ | ||
provider: 'mysql', | ||
}, | ||
{ | ||
provider: 'sqlserver', | ||
}, | ||
{ | ||
provider: 'cockroachdb', | ||
}, | ||
{ | ||
provider: 'mongodb', | ||
}, | ||
], | ||
]) |
19 changes: 19 additions & 0 deletions
19
packages/client/tests/functional/too-many-instances-of-prisma-client/prisma/_schema.ts
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,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)} | ||
} | ||
` | ||
}) |
36 changes: 36 additions & 0 deletions
36
packages/client/tests/functional/too-many-instances-of-prisma-client/tests.ts
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,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') | ||
}) | ||
}) |