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

Use aegir for testing js-libp2p #104

Merged
merged 12 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
34 changes: 22 additions & 12 deletions multidim-interop/go/v0.22/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"strconv"
"time"

"github.com/go-redis/redis/v8"
Expand All @@ -22,24 +23,33 @@ import (

func main() {
var (
transport = os.Getenv("transport")
secureChannel = os.Getenv("security")
muxer = os.Getenv("muxer")
isDialerStr = os.Getenv("is_dialer")
ip = os.Getenv("ip")
redis_addr = os.Getenv("REDIS_ADDR")
transport = os.Getenv("transport")
secureChannel = os.Getenv("security")
muxer = os.Getenv("muxer")
isDialerStr = os.Getenv("is_dialer")
ip = os.Getenv("ip")
testTimeoutStr = os.Getenv("test_timeout")
redisAddr = os.Getenv("REDIS_ADDR")
)

if redis_addr == "" {
redis_addr = "redis:6379"
var testTimeout = 10 * time.Second
if testTimeoutStr != "" {
secs, err := strconv.ParseInt(testTimeoutStr, 10, 32)
if err == nil {
testTimeout = time.Duration(secs) * time.Second
}
}

if redisAddr == "" {
redisAddr = "redis:6379"
}

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()

// Get peer information via redis
rClient := redis.NewClient(&redis.Options{
Addr: redis_addr,
Addr: redisAddr,
Password: "",
DB: 0,
})
Expand Down Expand Up @@ -102,7 +112,7 @@ func main() {
defer host.Close()

if is_dialer {
val, err := rClient.BLPop(ctx, 10*time.Second, "listenerAddr").Result()
val, err := rClient.BLPop(ctx, testTimeout, "listenerAddr").Result()
if err != nil {
panic("Failed to wait for listener to be ready")
}
Expand Down Expand Up @@ -137,7 +147,7 @@ func main() {
if err != nil {
panic("Failed to send listener address")
}
_, err = rClient.BLPop(ctx, 10*time.Second, "dialerDone").Result()
_, err = rClient.BLPop(ctx, testTimeout, "dialerDone").Result()
if err != nil {
panic("Failed to wait for dialer conclusion")
}
Expand Down
34 changes: 22 additions & 12 deletions multidim-interop/go/v0.23/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"strconv"
"time"

"github.com/go-redis/redis/v8"
Expand All @@ -23,24 +24,33 @@ import (

func main() {
var (
transport = os.Getenv("transport")
secureChannel = os.Getenv("security")
muxer = os.Getenv("muxer")
isDialerStr = os.Getenv("is_dialer")
ip = os.Getenv("ip")
redis_addr = os.Getenv("REDIS_ADDR")
transport = os.Getenv("transport")
secureChannel = os.Getenv("security")
muxer = os.Getenv("muxer")
isDialerStr = os.Getenv("is_dialer")
ip = os.Getenv("ip")
testTimeoutStr = os.Getenv("test_timeout")
redisAddr = os.Getenv("REDIS_ADDR")
)

if redis_addr == "" {
redis_addr = "redis:6379"
var testTimeout = 10 * time.Second
if testTimeoutStr != "" {
secs, err := strconv.ParseInt(testTimeoutStr, 10, 32)
if err == nil {
testTimeout = time.Duration(secs) * time.Second
}
}

if redisAddr == "" {
redisAddr = "redis:6379"
}

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()

// Get peer information via redis
rClient := redis.NewClient(&redis.Options{
Addr: redis_addr,
Addr: redisAddr,
Password: "",
DB: 0,
})
Expand Down Expand Up @@ -106,7 +116,7 @@ func main() {
defer host.Close()

if is_dialer {
val, err := rClient.BLPop(ctx, 10*time.Second, "listenerAddr").Result()
val, err := rClient.BLPop(ctx, testTimeout, "listenerAddr").Result()
if err != nil {
panic("Failed to wait for listener to be ready")
}
Expand Down Expand Up @@ -141,7 +151,7 @@ func main() {
if err != nil {
panic("Failed to send listener address")
}
_, err = rClient.BLPop(ctx, 10*time.Second, "dialerDone").Result()
_, err = rClient.BLPop(ctx, testTimeout, "dialerDone").Result()
if err != nil {
panic("Failed to wait for dialer conclusion")
}
Expand Down
34 changes: 22 additions & 12 deletions multidim-interop/go/v0.24/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"strconv"
"time"

"github.com/go-redis/redis/v8"
Expand All @@ -23,24 +24,33 @@ import (

func main() {
var (
transport = os.Getenv("transport")
secureChannel = os.Getenv("security")
muxer = os.Getenv("muxer")
isDialerStr = os.Getenv("is_dialer")
ip = os.Getenv("ip")
redis_addr = os.Getenv("REDIS_ADDR")
transport = os.Getenv("transport")
secureChannel = os.Getenv("security")
muxer = os.Getenv("muxer")
isDialerStr = os.Getenv("is_dialer")
ip = os.Getenv("ip")
testTimeoutStr = os.Getenv("test_timeout")
redisAddr = os.Getenv("REDIS_ADDR")
)

if redis_addr == "" {
redis_addr = "redis:6379"
var testTimeout = 10 * time.Second
if testTimeoutStr != "" {
secs, err := strconv.ParseInt(testTimeoutStr, 10, 32)
if err == nil {
testTimeout = time.Duration(secs) * time.Second
}
}

if redisAddr == "" {
redisAddr = "redis:6379"
}

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()

// Get peer information via redis
rClient := redis.NewClient(&redis.Options{
Addr: redis_addr,
Addr: redisAddr,
Password: "",
DB: 0,
})
Expand Down Expand Up @@ -111,7 +121,7 @@ func main() {
fmt.Println("My multiaddr is: ", host.Addrs())

if is_dialer {
val, err := rClient.BLPop(ctx, 10*time.Second, "listenerAddr").Result()
val, err := rClient.BLPop(ctx, testTimeout, "listenerAddr").Result()
if err != nil {
panic("Failed to wait for listener to be ready")
}
Expand Down Expand Up @@ -145,7 +155,7 @@ func main() {
if err != nil {
panic("Failed to send listener address")
}
_, err = rClient.BLPop(ctx, 10*time.Second, "dialerDone").Result()
_, err = rClient.BLPop(ctx, testTimeout, "dialerDone").Result()
if err != nil {
panic("Failed to wait for dialer conclusion")
}
Expand Down
90 changes: 90 additions & 0 deletions multidim-interop/js/v0.41/.aegir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { spawn, exec } from "child_process";
import { existsSync } from "fs";
import { createClient } from 'redis'
import http from "http"

const isDialer = process.env.is_dialer === "true"
const REDIS_ADDR = process.env.REDIS_ADDR || 'redis:6379'

// Used to preinstall the browsers in the docker image
const initialSetup = process.env.initial_setup === "true"
MarcoPolo marked this conversation as resolved.
Show resolved Hide resolved

/** @type {import('aegir/types').PartialOptions} */
export default {
test: {
async before() {
if (initialSetup) {
return {}
}

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)
MarcoPolo marked this conversation as resolved.
Show resolved Hide resolved
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 }) {
if (initialSetup) {
return
}

await new Promise(resolve => {
proxyServer.close(() => resolve());
})

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

FROM mcr.microsoft.com/playwright

WORKDIR /app


COPY package*.json .

RUN npm ci

# Install browsers
RUN ./node_modules/.bin/playwright install

COPY tsconfig.json .
COPY .aegir.js .
COPY test ./test
COPY src ./src

RUN npm run build

ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "browser" ]
12 changes: 8 additions & 4 deletions multidim-interop/js/v0.41/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# syntax=docker/dockerfile:1

FROM node:17
FROM node:18

WORKDIR /app

COPY package*.json .

RUN npm ci

COPY *.js /app/
COPY tsconfig.json .
COPY .aegir.js .
COPY test ./test
COPY src ./src

RUN npm run build

ENTRYPOINT [ "npm", "run", "start" ]
ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "node" ]
16 changes: 12 additions & 4 deletions multidim-interop/js/v0.41/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
image_name := js-v0.21
TEST_SOURCES := $(wildcard test/*.ts)

image.json: Dockerfile index.js package.json package-lock.json
IMAGE_NAME=${image_name} ../../dockerBuildWrapper.sh .
docker image inspect ${image_name} -f "{{.Id}}" | \
all: chromium-image.json node-image.json

chromium-image.json: ChromiumDockerfile $(TEST_SOURCES) package.json package-lock.json
IMAGE_NAME=chromium-${image_name} ../../dockerBuildWrapper.sh -f ChromiumDockerfile .
docker image inspect chromium-${image_name} -f "{{.Id}}" | \
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@

node-image.json: Dockerfile $(TEST_SOURCES) package.json package-lock.json
IMAGE_NAME=node-${image_name} ../../dockerBuildWrapper.sh -f Dockerfile .
docker image inspect node-${image_name} -f "{{.Id}}" | \
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@

.PHONY: clean

clean:
rm image.json
rm *image.json
Loading