Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a test with notablescan for MongoDB #24071

Merged
merged 6 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
})
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')