Skip to content

Commit

Permalink
test(client): add vitess flavor in relationMode test suite (#16051)
Browse files Browse the repository at this point in the history
Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
  • Loading branch information
jkomyno and Jolg42 committed Nov 2, 2022
1 parent 50235fe commit 3f34330
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 60 deletions.
18 changes: 18 additions & 0 deletions .buildkite/publish/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ services:
# Functional test URLS
- TEST_FUNCTIONAL_POSTGRES_URI=postgres://prisma:prisma@postgres:5432/PRISMA_DB_NAME
- TEST_FUNCTIONAL_MYSQL_URI=mysql://root:root@mysql:3306/PRISMA_DB_NAME
- TEST_FUNCTIONAL_VITESS_8_URI=mysql://root:root@localhost:33807/PRISMA_DB_NAME
- TEST_FUNCTIONAL_MSSQL_URI=sqlserver://mssql:1433;database=PRISMA_DB_NAME;user=SA;password=Pr1sm4_Pr1sm4;trustServerCertificate=true;
- TEST_FUNCTIONAL_MONGO_URI=mongodb://root:prisma@mongo:27018/PRISMA_DB_NAME?authSource=admin
- TEST_FUNCTIONAL_COCKROACH_URI=postgresql://prisma@cockroachdb:26257/PRISMA_DB_NAME
Expand Down Expand Up @@ -74,6 +75,9 @@ services:
- mongodb_migrate
- mongodb_migrate_seed
- cockroachdb
# TODO: uncomment when we test vitess in client functional test suite
# Currently we only test `relationMode` tests in GitHub Actions
# - vitess-8

postgres:
image: postgres:10
Expand Down Expand Up @@ -125,6 +129,20 @@ services:
ports:
- '3307:3306'

vitess-8:
image: vitess/vttestserver:mysql80@sha256:9412e3d51bde38e09c3039090b5c68808e299579f12c79178a4ec316f7831889
restart: always
ports:
- 33807:33807
environment:
PORT: '33804' # unused in testing, but required by vttestserver
KEYSPACES: 'keyspace' # unused in testing, but required by vttestserver
NUM_SHARDS: '1' # unused in testing, but required by vttestserver

MYSQL_BIND_HOST: '0.0.0.0'
FOREIGN_KEY_MODE: 'disallow'
VT_DIALECT: 'mysql80'

mariadb:
image: mariadb:10.7.3
restart: always
Expand Down
18 changes: 18 additions & 0 deletions .buildkite/test/docker-compose.14.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ services:
# Functional test URLS
- TEST_FUNCTIONAL_POSTGRES_URI=postgres://prisma:prisma@postgres:5432/PRISMA_DB_NAME
- TEST_FUNCTIONAL_MYSQL_URI=mysql://root:root@mysql:3306/PRISMA_DB_NAME
- TEST_FUNCTIONAL_VITESS_8_URI=mysql://root:root@localhost:33807/PRISMA_DB_NAME
- TEST_FUNCTIONAL_MSSQL_URI=sqlserver://mssql:1433;database=PRISMA_DB_NAME;user=SA;password=Pr1sm4_Pr1sm4;trustServerCertificate=true;
- TEST_FUNCTIONAL_MONGO_URI=mongodb://root:prisma@mongo:27018/PRISMA_DB_NAME?authSource=admin
- TEST_FUNCTIONAL_COCKROACH_URI=postgresql://prisma@cockroachdb:26257/PRISMA_DB_NAME
Expand All @@ -64,6 +65,9 @@ services:
- mongodb_migrate
- mongodb_migrate_seed
- cockroachdb
# TODO: uncomment when we test vitess in client functional test suite
# Currently we only test `relationMode` tests in GitHub Actions
# - vitess-8

postgres:
image: postgres:10
Expand Down Expand Up @@ -115,6 +119,20 @@ services:
ports:
- '3307:3306'

vitess-8:
image: vitess/vttestserver:mysql80@sha256:9412e3d51bde38e09c3039090b5c68808e299579f12c79178a4ec316f7831889
restart: always
ports:
- 33807:33807
environment:
PORT: '33804' # unused in testing, but required by vttestserver
KEYSPACES: 'keyspace' # unused in testing, but required by vttestserver
NUM_SHARDS: '1' # unused in testing, but required by vttestserver

MYSQL_BIND_HOST: '0.0.0.0'
FOREIGN_KEY_MODE: 'disallow'
VT_DIALECT: 'mysql80'

mariadb:
image: mariadb:10.7.3
restart: always
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
# CLIENT test:functional relationMode
#
client-relationMode:
timeout-minutes: 35
timeout-minutes: 60
runs-on: ${{ matrix.os }}

needs: detect_jobs_to_run
Expand Down Expand Up @@ -147,6 +147,7 @@ jobs:
TEST_COCKROACH_SHADOWDB_URI_MIGRATE: 'postgres://prisma:prisma@localhost:26257/tests-migrate-shadowdb'
TEST_FUNCTIONAL_POSTGRES_URI: 'postgres://prisma:prisma@localhost:5432/PRISMA_DB_NAME'
TEST_FUNCTIONAL_MYSQL_URI: 'mysql://root:root@localhost:3306/PRISMA_DB_NAME'
TEST_FUNCTIONAL_VITESS_8_URI: 'mysql://root:root@localhost:33807/PRISMA_DB_NAME'
TEST_FUNCTIONAL_MSSQL_URI: 'sqlserver://localhost:1433;database=PRISMA_DB_NAME;user=SA;password=Pr1sm4_Pr1sm4;trustServerCertificate=true;'
TEST_FUNCTIONAL_MONGO_URI: 'mongodb://root:prisma@localhost:27018/PRISMA_DB_NAME?authSource=admin'
TEST_FUNCTIONAL_COCKROACH_URI: 'postgresql://prisma@localhost:26257/PRISMA_DB_NAME'
Expand All @@ -160,7 +161,7 @@ jobs:
echo "RELATION_MODE=${{ matrix.relationMode }}"
if [ ! -z "${{ matrix.relationMode }}" ]; then echo "RELATION_MODE=${{ matrix.relationMode }}" >> $GITHUB_ENV; fi
- run: docker-compose -f docker/docker-compose.yml up --detach postgres mysql mssql mongo cockroachdb
- run: docker-compose -f docker/docker-compose.yml up --detach postgres mysql mssql mongo cockroachdb vitess-8

- uses: pnpm/action-setup@v2.2.4
with:
Expand All @@ -177,14 +178,17 @@ jobs:
SKIP_GIT: true
GITHUB_CONTEXT: ${{ toJson(github) }}

# shouldn't take more than 15 minutes
- name: 1 to 1
run: pnpm run test:functional:code --relation-mode-tests-only relationMode/tests_1-to-1.ts
working-directory: packages/client

# shouldn't take more than 15 minutes
- name: 1 to n
run: pnpm run test:functional:code --relation-mode-tests-only relationMode/tests_1-to-n.ts
working-directory: packages/client

# shouldn't take more than 15 minutes
- name: m to n (SQL databases)
run: pnpm run test:functional:code --relation-mode-tests-only relationMode/tests_m-to-n.ts
working-directory: packages/client
Expand Down Expand Up @@ -1033,7 +1037,7 @@ jobs:
CI: true
SKIP_GIT: true
GITHUB_CONTEXT: ${{ toJson(github) }}
NODE_OPTIONS: '--max-old-space-size=8096'
NODE_OPTIONS: '--max-old-space-size=10240' # allow Node.js to allocate at most 10gb of heap
JEST_JUNIT_SUITE_NAME: '${{ github.job }}/client/${{ matrix.os }}/node-${{ matrix.node }}/${{ matrix.queryEngine }}'

- uses: codecov/codecov-action@v3
Expand Down
1 change: 1 addition & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ To run tests requiring a database, start the test databases using Docker, see [D
# Prisma Client - Functional test suite
export TEST_FUNCTIONAL_POSTGRES_URI="postgres://prisma:prisma@localhost:5432/PRISMA_DB_NAME"
export TEST_FUNCTIONAL_MYSQL_URI="mysql://root:root@localhost:3306/PRISMA_DB_NAME"
export TEST_FUNCTIONAL_VITESS_8_URI="mysql://root:root@localhost:33807/PRISMA_DB_NAME"
export TEST_FUNCTIONAL_MSSQL_URI="sqlserver://localhost:1433;database=PRISMA_DB_NAME;user=SA;password=Pr1sm4_Pr1sm4;trustServerCertificate=true;"
export TEST_FUNCTIONAL_MONGO_URI="mongodb://root:prisma@localhost:27018/PRISMA_DB_NAME?authSource=admin"
export TEST_FUNCTIONAL_COCKROACH_URI="postgresql://prisma@localhost:26257/PRISMA_DB_NAME"
Expand Down
44 changes: 20 additions & 24 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ services:
# Planetscale
# From https://github.com/prisma/prisma-engines/blob/976a00ae3c30ab9507fa742986c9c6f5327ba10f/docker-compose.yml

vitess-8:
image: vitess/vttestserver:mysql80@sha256:9412e3d51bde38e09c3039090b5c68808e299579f12c79178a4ec316f7831889
restart: always
ports:
- 33807:33807
healthcheck:
test: ['CMD', 'mysqladmin', 'ping', '-h127.0.0.1', '-P33577']
interval: 5s
timeout: 2s
retries: 5
start_period: 25s
environment:
PORT: '33804' # unused in testing, but required by vttestserver
KEYSPACES: 'unsharded' # unused in testing, but required by vttestserver
NUM_SHARDS: '1' # unused in testing, but required by vttestserver
MYSQL_BIND_HOST: '0.0.0.0'
FOREIGN_KEY_MODE: 'disallow'
VT_DIALECT: 'mysql80'

# vitess-test-5_7:
# image: vitess/vttestserver:mysql57@sha256:2b132a22d08b3b227d9391f8f58ed7ab5c081ca07bf0f87a0c166729124d360a
# restart: always
Expand All @@ -44,19 +63,7 @@ services:
# NUM_SHARDS: "1"
# MYSQL_BIND_HOST: "0.0.0.0"
# FOREIGN_KEY_MODE: "disallow"

# vitess-test-8_0:
# image: vitess/vttestserver:mysql80@sha256:9412e3d51bde38e09c3039090b5c68808e299579f12c79178a4ec316f7831889
# restart: always
# ports:
# - 33807:33807
# environment:
# PORT: 33804
# KEYSPACES: 'test'
# NUM_SHARDS: '1'
# MYSQL_BIND_HOST: '0.0.0.0'
# FOREIGN_KEY_MODE: 'disallow'

#
# vitess-shadow-5_7:
# image: vitess/vttestserver:mysql57@sha256:2b132a22d08b3b227d9391f8f58ed7ab5c081ca07bf0f87a0c166729124d360a
# restart: always
Expand All @@ -69,17 +76,6 @@ services:
# MYSQL_BIND_HOST: "0.0.0.0"
# FOREIGN_KEY_MODE: "disallow"
#
# vitess-shadow-8_0:
# image: vitess/vttestserver:mysql80@sha256:9412e3d51bde38e09c3039090b5c68808e299579f12c79178a4ec316f7831889
# restart: always
# ports:
# - 33808:33807
# environment:
# PORT: 33804
# KEYSPACES: 'shadow'
# NUM_SHARDS: '1'
# MYSQL_BIND_HOST: '0.0.0.0'
# FOREIGN_KEY_MODE: 'disallow'

mysql:
image: mysql:8.0
Expand Down
3 changes: 2 additions & 1 deletion packages/client/tests/functional/_utils/getTestSuiteInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ function getTestSuiteParametersString(configs: Record<string, string>[]) {
// For `relationMode` tests
// we hardcode how it lookks like for test results
if (config.relationMode !== undefined) {
return `relationMode=${config.relationMode},provider=${config.provider},onUpdate=${config.onUpdate},onDelete=${config.onDelete},id=${config.id}`
const providerFlavorStr = config.providerFlavor === undefined ? '' : `providerFlavor=${config.providerFlavor},`
return `relationMode=${config.relationMode},provider=${config.provider},${providerFlavorStr}onUpdate=${config.onUpdate},onDelete=${config.onDelete},id=${config.id}`
} else {
const firstKey = Object.keys(config)[0]
return `${firstKey}=${config[firstKey]}`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Providers } from '../providers'

export enum ProviderFlavors {
VITESS_8 = 'vitess_8',
}

const providerFlavors = [...Object.values(Providers), ProviderFlavors.VITESS_8] as const
export type ProviderFlavor = typeof providerFlavors[number]

export function getProviderFromFlavor(providerFlavor: ProviderFlavor): Providers {
switch (providerFlavor) {
case ProviderFlavors.VITESS_8:
return Providers.MYSQL
default:
return providerFlavor
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { Providers } from '../providers'
import { getProviderFromFlavor, ProviderFlavor, ProviderFlavors } from './ProviderFlavor'

type ComputeMatrix = {
relationMode: 'prisma' | 'foreignKeys' | ''
providersDenyList?: Providers[]
providersDenyList?: ProviderFlavor[]
}

export function computeMatrix({ relationMode, providersDenyList }: ComputeMatrix) {
const providersBase = [
const providerFlavorsBase = [
Providers.POSTGRESQL,
Providers.COCKROACHDB,
Providers.SQLSERVER,
Providers.MYSQL,
Providers.SQLITE,
Providers.MYSQL,
ProviderFlavors.VITESS_8,
] as const
// Note: SetDefault is not implemented in the emulation (relationMode="prisma")

Expand All @@ -22,7 +24,9 @@ export function computeMatrix({ relationMode, providersDenyList }: ComputeMatrix

const referentialActionsBase = ['DEFAULT', 'Cascade', 'NoAction', 'Restrict', 'SetNull'] as const

const providers = providersBase.filter((provider) => !(providersDenyList || []).includes(provider))
const providerFlavors = providerFlavorsBase.filter(
(provideFlavor) => !(providersDenyList || []).includes(provideFlavor),
)

// "foreignKeys"
//
Expand All @@ -42,9 +46,12 @@ export function computeMatrix({ relationMode, providersDenyList }: ComputeMatrix
//
// We skip these combinations in the matrix (= filtering them out)

const referentialActionsDenylistByProvider = {
const referentialActionsDenylistByProviderFlavor = {
foreignKeys: {
[Providers.SQLSERVER]: ['Restrict'],

// skip all actions for Vitess & relationMode="foreignKeys" as Foreign Keys are not supported by that provider
[ProviderFlavors.VITESS_8]: referentialActionsBase,
},
prisma: {
[Providers.SQLSERVER]: ['Restrict'],
Expand All @@ -53,14 +60,16 @@ export function computeMatrix({ relationMode, providersDenyList }: ComputeMatrix
},
}

const providersMatrix = providers.map((provider) => ({
provider,
const providersMatrix = providerFlavors.map((providerFlavor) => ({
provider: getProviderFromFlavor(providerFlavor),
providerFlavor,
id: 'String @id',
relationMode,
}))

const referentialActionsMatrix = providersMatrix.flatMap((entry) => {
const denyList = referentialActionsDenylistByProvider[relationMode || 'foreignKeys'][entry.provider] || []
const denyList =
referentialActionsDenylistByProviderFlavor[relationMode || 'foreignKeys'][entry.providerFlavor] || []
const referentialActions = referentialActionsBase.filter((action) => !denyList.includes(action))

const referentialActionMatrixForSQL = referentialActions.map((referentialAction) => ({
Expand All @@ -78,6 +87,7 @@ export function computeMatrix({ relationMode, providersDenyList }: ComputeMatrix
if (!relationMode || relationMode === 'prisma') {
const mongoDBMatrixBase = {
provider: Providers.MONGODB,
providerFlavor: getProviderFromFlavor(Providers.MONGODB),
id: 'String @id @map("_id")',
relationMode: 'prisma',
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { match } from 'ts-pattern'

import { Providers } from '../providers'
import type { ProviderFlavor } from './ProviderFlavor'

export type ComputeSchemaHeader = {
provider: Providers
providerFlavor: ProviderFlavor
previewFeatures: string
relationMode: string
}

export function computeSchemaHeader({ provider, previewFeatures, relationMode }: ComputeSchemaHeader): string {
const USE_PLANETSCALE = false

export function computeSchemaHeader({
provider,
providerFlavor,
previewFeatures,
relationMode,
}: ComputeSchemaHeader): string {
// if relationModeLine is not defined, we do not add the line
// if relationModeLine is defined
// we add the line only if the provider is not MongoDB, since MongoDB doesn't need the setting, it's on by default
const relationModeLine = provider === Providers.MONGODB || !relationMode ? '' : `relationMode = "${relationMode}"`

const url = match(provider)
.when(
(_provider) => USE_PLANETSCALE && _provider === Providers.MYSQL,
(_provider) => `"mysql://root:root@127.0.0.1:33807/PRISMA_DB_NAME"`,
)
.with(Providers.SQLITE, (_provider) => `"file:test.db"`)
.otherwise((_provider) => `env("DATABASE_URI_${provider}")`)
const url = match({ provider, providerFlavor })
.with({ provider: Providers.SQLITE }, () => `"file:test.db"`)
.otherwise(({ providerFlavor }) => `env("DATABASE_URI_${providerFlavor}")`)

const schemaHeader = /* Prisma */ `
generator client {
Expand Down

0 comments on commit 3f34330

Please sign in to comment.