Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add multidimensional interop test #1615

Merged
merged 17 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ChromiumDockerfile
Dockerfile
35 changes: 35 additions & 0 deletions .github/workflows/interop-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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@master
with:
test-filter: js-libp2p-head
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"
MarcoPolo marked this conversation as resolved.
Show resolved Hide resolved

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'
MarcoPolo marked this conversation as resolved.
Show resolved Hide resolved
}
}
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
18 changes: 18 additions & 0 deletions interop/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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" ]
31 changes: 31 additions & 0 deletions interop/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
image_name := js-libp2p-head
TEST_SOURCES := $(wildcard test/*.ts)

# Enable webkit once https://github.com/libp2p/js-libp2p/pull/1627 is in
# all: node-image.json webkit-image.json firefox-image.json chromium-image.json
all: node-image.json firefox-image.json chromium-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"
]
}
21 changes: 21 additions & 0 deletions interop/firefox-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"id": "firefox-js-libp2p-head",
"containerImageID": "firefox-js-libp2p-head",
"transports": [
{
"name": "webrtc",
"onlyDial": true
},
{
"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": "^12.0.0",
"@chainsafe/libp2p-yamux": "^4.0.1",
"@libp2p/mplex": "^8.0.1",
"@libp2p/tcp": "^7.0.1",
"@libp2p/webrtc": "^2.0.2",
"@libp2p/websockets": "^6.0.1",
"@libp2p/webtransport": "^2.0.1",
"@multiformats/mafmt": "^12.1.2",
"@multiformats/multiaddr": "^12.1.3",
"libp2p": "../",
"node-fetch": "^3.3.0",
MarcoPolo marked this conversation as resolved.
Show resolved Hide resolved
"playwright": "^1.31.2",
MarcoPolo marked this conversation as resolved.
Show resolved Hide resolved
"redis": "4.5.1"
},
"browser": {
"@libp2p/tcp": false
},
"devDependencies": {
"aegir": "^38.1.0",
MarcoPolo marked this conversation as resolved.
Show resolved Hide resolved
"standard": "^17.0.0",
"typescript": "^4.9.4"
MarcoPolo marked this conversation as resolved.
Show resolved Hide resolved
},
"overrides": {
"playwright-core": "^1.31.2"
}
MarcoPolo marked this conversation as resolved.
Show resolved Hide resolved
}
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