Skip to content

Commit

Permalink
Add libp2p-ping-interop test
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed May 1, 2023
1 parent 53b1645 commit d4b000d
Show file tree
Hide file tree
Showing 15 changed files with 494 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ChromiumDockerfile
Dockerfile
36 changes: 36 additions & 0 deletions .github/workflows/interop-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Interoperability Testing
on:
pull_request:
push:
branches:
- "master"

jobs:
run-multidim-interop:
name: Run multidimensional interoperability tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: ipfs/aegir/actions/cache-node-modules@master
with:
directories: |
./interop/node_modules
- name: Build interop
run: (cd interop && npm i && npm run build)
- name: Build images
run: (cd interop && make)
# - name: Save package-lock.json as artifact
# uses: actions/upload-artifact@v2
# with:
# name: package locks
# path: |
# package-lock.json
# interop/package-lock.json
- uses: libp2p/test-plans/.github/actions/run-interop-ping-test@marco/image-caching
with:
test-filter: js-libp2p-head
extra-versions: ${{ github.workspace }}/interop/node-version.json
# extra-versions: ${{ github.workspace }}/interop/node-version.json ${{ github.workspace }}/interop/chromium-version.json ${{ github.workspace }}/interop/firefox-version.json
s3-cache-bucket: ${{ vars.S3_LIBP2P_BUILD_CACHE_BUCKET_NAME }}
s3-access-key-id: ${{ vars.S3_LIBP2P_BUILD_CACHE_AWS_ACCESS_KEY_ID }}
s3-secret-access-key: ${{ secrets.S3_LIBP2P_BUILD_CACHE_AWS_SECRET_ACCESS_KEY }}
82 changes: 82 additions & 0 deletions interop/.aegir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { createClient } from 'redis'
import http from "http"

const redis_addr = process.env.redis_addr || 'redis:6379'

/** @type {import('aegir/types').PartialOptions} */
export default {
test: {
browser: {
config: {
// Ignore self signed certificates
browserContextOptions: { ignoreHTTPSErrors: true }
}
},
async before() {
const redisClient = createClient({
url: `redis://${redis_addr}`
})
redisClient.on('error', (err) => console.error(`Redis Client Error: ${err}`))
await redisClient.connect()

const requestListener = async function (req, res) {
const requestJSON = await new Promise(resolve => {
let body = ""
req.on('data', function (data) {
body += data;
});

req.on('end', function () {
resolve(JSON.parse(body))
});
})

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

res.writeHead(200, {
'Access-Control-Allow-Origin': '*'
})
res.end(JSON.stringify(redisRes))
} catch (err) {
console.error("Error in redis command:", err)
res.writeHead(500, {
'Access-Control-Allow-Origin': '*'
})
res.end(err.toString())
return
}


};

const proxyServer = http.createServer(requestListener);
await new Promise(resolve => { proxyServer.listen(0, "localhost", () => { resolve() }); })

return {
redisClient,
proxyServer: proxyServer,
env: {
...process.env,
proxyPort: proxyServer.address().port
}
}
},
async after(_, { proxyServer, redisClient }) {
await new Promise(resolve => {
proxyServer.close(() => resolve());
})

try {
// We don't care if this fails
await redisClient.disconnect()
} catch { }
}
},
build: {
bundlesizeMax: '18kB'
}
}
5 changes: 5 additions & 0 deletions interop/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist
node-image.json
chromium-image.json
firefox-image.json
webkit-image.json
11 changes: 11 additions & 0 deletions interop/BrowserDockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# syntax=docker/dockerfile:1

FROM mcr.microsoft.com/playwright

COPY --from=node-js-libp2p-head /app/ /app/
WORKDIR /app/interop
RUN ./node_modules/.bin/playwright install
ARG BROWSER=chromium # Options: chromium, firefox, webkit
ENV BROWSER=$BROWSER

ENTRYPOINT npm test -- --build false --types false -t browser -- --browser $BROWSER
41 changes: 41 additions & 0 deletions interop/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# syntax=docker/dockerfile:1

# FROM node:18 AS builder

# WORKDIR /app
# COPY package.json .
# COPY package-lock.json .
# RUN npm ci
# WORKDIR /app/interop
# COPY ./interop/package.json .
# COPY ./interop/package-lock.json .
# RUN npm ci

# FROM node:18

# WORKDIR /app
# COPY . .
# COPY --from=builder /app/node_modules /app/node_modules
# RUN npm run build
# WORKDIR /app/interop
# COPY --from=builder /app/interop/node_modules /app/interop/node_modules
# RUN npm run build

FROM node:18
WORKDIR /app
COPY package.json .
COPY ./node_modules ./node_modules

WORKDIR /app/interop
COPY ./interop/node_modules ./node_modules

WORKDIR /app
COPY ./dist ./dist

WORKDIR /app/interop
COPY ./interop/dist ./dist

COPY ./interop/package.json .
COPY ./interop/.aegir.js .

ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "node" ]
30 changes: 30 additions & 0 deletions interop/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
image_name := js-libp2p-head
TEST_SOURCES := $(wildcard test/*.ts)

# all: webkit-image.json firefox-image.json chromium-image.json node-image.json
all: node-image.json

node-image.json: Dockerfile $(TEST_SOURCES) package.json .aegir.js
cd .. && docker build -f interop/Dockerfile -t node-${image_name} .
docker image inspect node-${image_name} -f "{{.Id}}" | \
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@

chromium-image.json: node-image.json BrowserDockerfile $(TEST_SOURCES) package.json .aegir.js
cd .. && docker build -f interop/BrowserDockerfile --build-arg=BROWSER=chromium -t chromium-${image_name} .
docker image inspect chromium-${image_name} -f "{{.Id}}" | \
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@

firefox-image.json: node-image.json BrowserDockerfile $(TEST_SOURCES) package.json .aegir.js
cd .. && docker build -f interop/BrowserDockerfile --build-arg=BROWSER=firefox -t firefox-${image_name} .
docker image inspect firefox-${image_name} -f "{{.Id}}" | \
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@

webkit-image.json: node-image.json BrowserDockerfile $(TEST_SOURCES) package.json .aegir.js
cd .. && docker build -f interop/BrowserDockerfile --build-arg=BROWSER=webkit -t webkit-${image_name} .
docker image inspect webkit-${image_name} -f "{{.Id}}" | \
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@

.PHONY: clean

clean:
rm *image.json
25 changes: 25 additions & 0 deletions interop/chromium-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"id": "chromium-js-libp2p-head",
"containerImageID": "chromium-js-libp2p-head",
"transports": [
{
"name": "webtransport",
"onlyDial": true
},
{
"name": "webrtc",
"onlyDial": true
},
{
"name": "wss",
"onlyDial": true
}
],
"secureChannels": [
"noise"
],
"muxers": [
"mplex",
"yamux"
]
}
17 changes: 17 additions & 0 deletions interop/firefox-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"id": "firefox-js-libp2p-head",
"containerImageID": "firefox-js-libp2p-head",
"transports": [
{
"name": "wss",
"onlyDial": true
}
],
"secureChannels": [
"noise"
],
"muxers": [
"mplex",
"yamux"
]
}
19 changes: 19 additions & 0 deletions interop/node-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"id": "node-js-libp2p-head",
"containerImageID": "node-js-libp2p-head",
"transports": [
"tcp",
"ws",
{
"name": "wss",
"onlyDial": true
}
],
"secureChannels": [
"noise"
],
"muxers": [
"mplex",
"yamux"
]
}
44 changes: 44 additions & 0 deletions interop/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "multidim-interop",
"private": true,
"version": "1.0.0",
"description": "Multidimension Interop Test",
"type": "module",
"main": "index.js",
"author": "Glen De Cauwsemaecker <[email protected]> / @marcopolo",
"license": "MIT",
"engines": {
"node": ">=18"
},
"scripts": {
"start": "node index.js",
"build": "aegir build",
"test": "aegir test"
},
"dependencies": {
"@chainsafe/libp2p-noise": "^10.2.0",
"@chainsafe/libp2p-yamux": "^3.0.4",
"@libp2p/mplex": "^7.1.1",
"@libp2p/tcp": "^6.0.8",
"@libp2p/webrtc": "^1.0.3",
"@libp2p/websockets": "^5.0.4",
"@libp2p/webtransport": "^1.0.7",
"@multiformats/mafmt": "^11.1.0",
"@multiformats/multiaddr": "^11.1.4",
"libp2p": "../",
"node-fetch": "^3.3.0",
"playwright": "^1.31.2",
"redis": "4.5.1"
},
"browser": {
"@libp2p/tcp": false
},
"devDependencies": {
"aegir": "^38.1.0",
"standard": "^17.0.0",
"typescript": "^4.9.4"
},
"overrides": {
"playwright-core": "^1.31.2"
}
}
3 changes: 3 additions & 0 deletions interop/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
console.log("Everything is defined in the test folder")

export { }
Loading

0 comments on commit d4b000d

Please sign in to comment.