diff --git a/cmd/testproxy/main.go b/cmd/testproxy/main.go index 5c46d7b..4011eb8 100644 --- a/cmd/testproxy/main.go +++ b/cmd/testproxy/main.go @@ -32,7 +32,7 @@ func main() { } if err := db.Ping(ctx); err != nil { - logger.Fatal("failed to ping db", zap.Error(err)) + logger.Fatal("failed to ping db", zap.Error(err), zap.String("url", os.Getenv("DATABASE_URL"))) } connections := make(map[string]net.Conn) diff --git a/features/support/steps/backend.ts b/features/support/steps/backend.ts index 3d34b7d..d110c9c 100644 --- a/features/support/steps/backend.ts +++ b/features/support/steps/backend.ts @@ -3,7 +3,7 @@ import { After, Given } from '@cucumber/cucumber' import { World } from '../world' Given('the {string} backend is running', async function (this: World, backend: string) { - return await new Promise(resolve => { + return await new Promise((resolve, reject) => { const port = 10000 + Math.ceil(Math.random() * 1000) const env: NodeJS.ProcessEnv = { ...process.env, @@ -11,7 +11,7 @@ Given('the {string} backend is running', async function (this: World, backend: s ENV: 'test' } - if (this.databaseURL === undefined) { + if (this.databaseURL !== undefined) { env.DATABASE_URL = this.databaseURL } @@ -20,14 +20,21 @@ Given('the {string} backend is running', async function (this: World, backend: s env }) prc.stderr.setEncoding('utf8') + + let resolved = false prc.stderr.on('data', (data: string) => { const lines = data.split('\n') lines.forEach(line => { try { const entry = JSON.parse(line) + const severity = entry.severity.toLowerCase() + if (!resolved && (severity === 'error' || severity === 'emergency')) { + return reject(new Error('error before backend was started: ' + entry.message)) + } if (entry.message === 'using database') { this.databaseURL = entry.url } else if (entry.message === 'listening') { + resolved = true resolve(undefined) } } catch (_) { @@ -37,6 +44,10 @@ Given('the {string} backend is running', async function (this: World, backend: s }) prc.addListener('exit', () => { this.print(`${backend} exited`) + + if (!resolved) { + reject(new Error(`${backend} exited before it was ready`)) + } }) // Create a promise that resolves when the backend is closed so diff --git a/features/support/steps/network.ts b/features/support/steps/network.ts index 5222c0c..9cf62ee 100644 --- a/features/support/steps/network.ts +++ b/features/support/steps/network.ts @@ -90,8 +90,6 @@ Given('these lobbies exist:', async function (this: World, lobbies: DataTable) { values.push(`(${v.join(', ')})`) }) - console.log('INSERT INTO lobbies (' + columns.join(', ') + ') VALUES ' + values.join(', ')) - await fetch(`${this.testproxyURL}/sql`, { method: 'POST', body: 'INSERT INTO lobbies (' + columns.join(', ') + ') VALUES ' + values.join(', ')