Skip to content

Commit

Permalink
feat: add a test with notablescan for MongoDB (#24071)
Browse files Browse the repository at this point in the history
  • Loading branch information
laplab committed May 15, 2024
1 parent b84f46a commit bcc0a64
Show file tree
Hide file tree
Showing 9 changed files with 635 additions and 2 deletions.
35 changes: 33 additions & 2 deletions packages/client/tests/e2e/_utils/run.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { arg } from '@prisma/internals'
import { existsSync } from 'fs'
import { createReadStream, existsSync } from 'fs'
import fs from 'fs/promises'
import glob from 'globby'
import path from 'path'
import { pipeline } from 'stream/promises'
import { $, ProcessOutput, sleep } from 'zx'

const monorepoRoot = path.resolve(__dirname, '..', '..', '..', '..', '..')
Expand Down Expand Up @@ -116,6 +117,12 @@ async function main() {
return async () => {
const result =
await $`docker compose ${composeFileArgs} -p ${projectName} run --rm ${dockerVolumeArgs} -e "NAME=${testPath}" test-e2e`.nothrow()

await $`docker compose ${composeFileArgs} -p ${projectName} logs > ${path.join(
e2eRoot,
testPath,
'LOGS.docker.txt',
)}`
await $`docker compose ${composeFileArgs} -p ${projectName} stop`
await $`docker compose ${composeFileArgs} -p ${projectName} rm -f`
await $`docker network rm -f ${networkName}`
Expand Down Expand Up @@ -159,7 +166,15 @@ async function main() {
if (args['--verbose'] === true) {
for (const result of failedJobResults) {
console.log(`🛑 ${result.name} failed with exit code`, result.exitCode)
await $`cat ${path.resolve(__dirname, '..', result.name, 'LOGS.txt')}`

const logsPath = path.resolve(__dirname, '..', result.name, 'LOGS.txt')
const dockerLogsPath = path.resolve(__dirname, '..', result.name, 'LOGS.docker.txt')

if (await isFile(logsPath)) {
await printFile(logsPath)
} else if (await isFile(dockerLogsPath)) {
await printFile(dockerLogsPath)
}
await sleep(50) // give some time for the logs to be printed (CI issue)
}
}
Expand All @@ -182,6 +197,22 @@ async function restoreOriginalState() {
}
}

async function printFile(filePath: string) {
await pipeline(createReadStream(filePath), process.stdout)
}

async function isFile(filePath: string) {
try {
const stat = await fs.stat(filePath)
return stat.isFile()
} catch (e) {
if (e.code === 'ENOENT') {
return false
}
throw e
}
}

process.on('SIGINT', async () => {
await restoreOriginalState()
process.exit(0)
Expand Down
19 changes: 19 additions & 0 deletions packages/client/tests/e2e/mongodb-notablescan/_steps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { $ } from 'zx'

import { executeSteps } from '../_utils/executeSteps'

void executeSteps({
setup: async () => {
await $`pnpm install`
await $`pnpm prisma version`
await $`pnpm prisma generate`
await $`pnpm prisma db push --force-reset --skip-generate`
},
test: async () => {
await $`pnpm jest`
},
finish: async () => {
await $`echo "done"`
},
// keep: true, // keep docker open to debug it
})
19 changes: 19 additions & 0 deletions packages/client/tests/e2e/mongodb-notablescan/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.7'
services:
test-e2e:
environment:
- DATABASE_URL=mongodb://mongo:27017/test_db?retryWrites=true&replicaSet=rs0&directConnection=true
depends_on:
mongo:
condition: service_healthy

mongo:
image: mongo:7.0
command: ['--replSet', 'rs0', '--bind_ip_all', '--port', '27017', '--setParameter', 'notablescan=1']
healthcheck:
test: 'mongosh --port 27017 --eval "try { rs.status() } catch (err) { rs.initiate({_id:\"rs0\",members:[{_id:0,host:\"localhost:27017\"}]}); throw err; }"'
interval: 5s
timeout: 30s
start_period: 0s
start_interval: 1s
retries: 30
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../jest.config')
14 changes: 14 additions & 0 deletions packages/client/tests/e2e/mongodb-notablescan/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"private": true,
"version": "0.0.0",
"main": "index.js",
"scripts": {},
"dependencies": {
"@prisma/client": "/tmp/prisma-client-0.0.0.tgz"
},
"devDependencies": {
"@types/jest": "29.5.12",
"@types/node": "16.18.96",
"prisma": "/tmp/prisma-0.0.0.tgz"
}
}

0 comments on commit bcc0a64

Please sign in to comment.