Skip to content

Commit

Permalink
Add second setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Walker-GM committed Jun 9, 2023
1 parent 282cb2c commit e6ffbca
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 33 deletions.
2 changes: 1 addition & 1 deletion tasks/benchmark/k6/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function () {
})
}

const url = 'http://localhost:8910/.redwood/functions/graphql'
const url = 'http://localhost:8911/graphql'
const params = {
headers: {
'Content-Type': 'application/json',
Expand Down
18 changes: 0 additions & 18 deletions tasks/benchmark/runner.js

This file was deleted.

42 changes: 42 additions & 0 deletions tasks/benchmark/setups/default_unsafe_context/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env node
/* eslint-env node, es6*/

const path = require('path')

const fs = require('fs-extra')

const REDWOOD_PROJECT_DIRECTORY = process.argv.slice(2)[0]

function main() {
// Copy over SDL
fs.copyFileSync(
path.join('.', 'templates', 'benchmark.sdl.ts'),
path.join(
REDWOOD_PROJECT_DIRECTORY,
'api',
'src',
'graphql',
'benchmark.sdl.ts'
)
)

// Copy over the service
const benchmarkServicePath = path.join(
REDWOOD_PROJECT_DIRECTORY,
'api',
'src',
'services',
'benchmarks'
)
fs.mkdirSync(benchmarkServicePath)
fs.copyFileSync(
path.join('.', 'templates', 'benchmarks.ts'),
path.join(benchmarkServicePath, 'benchmarks.ts')
)

// Set DISABLE_CONTEXT_ISOLATION=1
const dotEnvPath = path.join(REDWOOD_PROJECT_DIRECTORY, '.env')
const dotEnvFile = fs.readFileSync(dotEnvPath, 'utf8')
fs.writeFileSync(dotEnvPath, `${dotEnvFile}\nDISABLE_CONTEXT_ISOLATION=1\n`)
}
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const schema = gql`
type MagicNumber {
value: Int!
}
type Mutation {
magicNumber(value: Int!): MagicNumber! @skipAuth
}
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { MutationResolvers } from 'types/graphql'

import { setContext } from '@redwoodjs/graphql-server'

import { logger } from 'src/lib/logger'

export const magicNumber: MutationResolvers['magicNumber'] = async ({
value,
}) => {
setContext({
// ...context,
magicNumber: value,
})
// context.magicNumber = value

const sleep = Math.random() * 200
// logger.info(`Sleeping for ${sleep}ms`)
await new Promise((resolve) => setTimeout(resolve, sleep))

const numberFromContext = (context.magicNumber ?? -1) as number
if (value !== numberFromContext) {
logger.error(`Expected ${value} but got ${numberFromContext}`)
// throw new Error(`Expected ${value} but got ${numberFromContext}`)
}

return { value: numberFromContext }
}
32 changes: 18 additions & 14 deletions tasks/run-benchmark
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,14 @@ async function main() {
console.log('Running test: ', test)

// Build the app
await execa('yarn', ['rw', 'build'], {
await execa('yarn', ['rw', 'build', 'api'], {
cwd: REDWOOD_PROJECT_DIRECTORY,
// shell: true,
// stdio: 'inherit',
})

// Start the serve
const serverExeca = execa('yarn', ['rw', 'serve'], {
const serverExeca = execa('yarn', ['rw', 'serve', 'api'], {
cwd: REDWOOD_PROJECT_DIRECTORY,
// shell: true,
stdio: 'pipe',
Expand All @@ -330,21 +330,25 @@ async function main() {
}

// Run k6 test
await execa(
'k6',
['run', '--out', 'json=k6_output.json', path.join(testsDir, test)],
{
cwd: REDWOOD_PROJECT_DIRECTORY,
// shell: true,
stdio: 'inherit',
}
)
try {
await execa(
'k6',
['run', '--out', 'json=k6_output.json', path.join(testsDir, test)],
{
cwd: REDWOOD_PROJECT_DIRECTORY,
// shell: true,
stdio: 'inherit',
}
)

// Collect the results
// TODO: Collect the results
} catch (_error) {
console.warn('The k6 test failed')
}

// Stop the serve
serverExeca.kill()

// Collect the results
// TODO: Collect the results
}
}
}
Expand Down

0 comments on commit e6ffbca

Please sign in to comment.