Skip to content

Commit

Permalink
chore: simplify interop test implementation (#2558)
Browse files Browse the repository at this point in the history
Aligns interop test implementation with libp2p/test-plans#365
  • Loading branch information
achingbrain committed Jun 6, 2024
1 parent 9e5835e commit bc6556f
Show file tree
Hide file tree
Showing 17 changed files with 359 additions and 1,063 deletions.
42 changes: 34 additions & 8 deletions interop/.aegir.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-console */
import http from 'http'
import { pEvent } from 'p-event'
import { createClient } from 'redis'
import { createRelay } from './relay.js'

const redisAddr = process.env.redis_addr || 'redis:6379'
const transport = process.env.transport
Expand All @@ -16,6 +17,8 @@ export default {
}
},
async before () {
const { createRelay } = await import('./dist/test/fixtures/relay.js')

let relayNode = { stop: () => {} }
let relayAddr = ''
if (transport === 'webrtc' && !isDialer) {
Expand All @@ -31,9 +34,14 @@ export default {
const redisClient = createClient({
url: `redis://${redisAddr}`
})
// eslint-disable-next-line no-console
redisClient.on('error', (err) => console.error(`Redis Client Error: ${err}`))
redisClient.on('error', (err) => {
console.error('Redis client error:', err)
})

let start = Date.now()
console.error('connect redis client')
await redisClient.connect()
console.error('connected redis client after', Date.now() - start, 'ms')

const requestListener = async function (req, res) {
const requestJSON = await new Promise(resolve => {
Expand All @@ -49,8 +57,18 @@ export default {

try {
const redisRes = await redisClient.sendCommand(requestJSON)
if (redisRes === null) {
throw new Error('redis sent back null')

if (redisRes == null) {
console.error('Redis failure - sent', requestJSON, 'received', redisRes)

res.writeHead(500, {
'Access-Control-Allow-Origin': '*'
})
res.end(JSON.stringify({
message: 'Redis sent back null'
}))

return
}

res.writeHead(200, {
Expand All @@ -67,17 +85,25 @@ export default {
}
}

start = Date.now()
console.error('start proxy server')
const proxyServer = http.createServer(requestListener)
await new Promise(resolve => { proxyServer.listen(0, () => { resolve() }) })
proxyServer.listen(0)

await pEvent(proxyServer, 'listening', {
signal: AbortSignal.timeout(5000)
})

console.error('redis proxy is listening on port', proxyServer.address().port, 'after', Date.now() - start, 'ms')

return {
redisClient,
relayNode,
proxyServer,
env: {
...process.env,
relayAddr,
proxyPort: proxyServer.address().port
RELAY_ADDR: relayAddr,
REDIS_PROXY_PORT: proxyServer.address().port
}
}
},
Expand Down
5 changes: 0 additions & 5 deletions interop/.gitignore

This file was deleted.

25 changes: 18 additions & 7 deletions interop/BrowserDockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# syntax=docker/dockerfile:1

# Copied since we won't have the repo to use if expanding from cache.

# Workaround: https://github.com/docker/cli/issues/996
ARG BASE_IMAGE=node-js-libp2p-head
FROM ${BASE_IMAGE} as js-libp2p-base

FROM mcr.microsoft.com/playwright

COPY --from=node-js-libp2p-head /app/ /app/
WORKDIR /app/interop
COPY --from=js-libp2p-base /app/ /app/

# We install browsers here instead of the cached version so that we use the latest browsers at run time.
# Ideally this would also be pinned, but playwright controls this, so there isn't much we can do about it.
# By installing here, we avoid installing it at test time.
RUN npx playwright install-deps
RUN npx playwright install

# Options: chromium, firefox, webkit
ARG BROWSER=chromium
ENV BROWSER=$BROWSER
# disable colored output and CLI animation from test runners
ENV CI true
ENV BROWSER=${BROWSER}

WORKDIR /app/interop

# manually specify runner until https://github.com/hugomrdias/playwright-test/issues/572 is resolved
ENTRYPOINT npm run test:interop:multidim -- --build false --types false -t browser -- --browser $BROWSER
ENTRYPOINT npm test -- -t browser -- --browser $BROWSER
Loading

0 comments on commit bc6556f

Please sign in to comment.