From fb21eac03f03d8226d82e43070e5e8d539689901 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Wed, 5 Jun 2024 20:56:10 +0000 Subject: [PATCH] Port GHA compose tests to use dctest. --- .github/workflows/push.yml | 44 ++++------------------- package.json | 7 ++-- test/basics.yaml | 71 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 40 deletions(-) create mode 100644 test/basics.yaml diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index eddf212..e9d34ba 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -46,47 +46,17 @@ jobs: - name: Run npm tests run: node build/test.js - compose-tests: + dctest-compose-tests: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 - - name: dhcp test - run: | - echo "COMPOSE_PROFILES=dhcp" > .env - docker-compose up --force-recreate -d - while ! docker-compose logs net | grep "Creating veth"; do - echo "Waiting for compose startup, sleeping 2 seconds"; sleep 2 - done - while true; do - [ $(docker-compose logs | grep "client.*ACK from" | wc -l) -ge 4 ] && break - echo "Waiting for 4 client ACKs, sleeping 2 second"; sleep 2 - done - docker-compose down --remove-orphans -t1 + - name: npm install dctest + run: npm install @lonocloud/dctest --no-save --ignore-scripts - - name: ping test - run: | - echo "COMPOSE_PROFILES=ping" > .env - docker-compose up --force-recreate -d - while ! docker-compose logs net | grep "Creating veth"; do - echo "Waiting for compose startup, sleeping 2 seconds"; sleep 2 - done - while true; do - [ $(docker-compose logs | grep "echo-reply" | wc -l) -ge 2 ] && break - echo "Waiting for 2+ echo replies, sleeping 2 second"; sleep 2 - done - docker-compose down --remove-orphans -t1 + - name: compose build (dhcp,ping,mac2ip profiles) + run: docker compose --profile dhcp --profile ping --profile mac2ip build - - name: mac2ip test - run: | - echo "COMPOSE_PROFILES=mac2ip" > .env - docker-compose up --force-recreate -d - while ! docker-compose logs net | grep "Creating veth"; do - echo "Waiting for compose startup, sleeping 2 seconds"; sleep 2 - done - while true; do - [ $(docker-compose logs | grep -o "worker-.*ACK to" | sort | uniq | wc -l) -ge 2 ] && break - echo "Waiting for 2+ uniq workers to ACK, sleeping 2 second"; sleep 2 - done - docker-compose down --remove-orphans -t1 + - name: run dctest tests + run: time node_modules/.bin/dctest --verbose-commands clj-protocol-test test/basics.yaml diff --git a/package.json b/package.json index 3b46da9..ebfa84c 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,6 @@ "description": "clj-protocol - Declarative protocol library", "repository": "https://github.com/LonoCloud/clj-protocol", "license": "SEE LICENSE IN LICENSE", - "devDependencies": { - "shadow-cljs": "2.14.4" - }, "dependencies": { "ffi-napi": "^4.0.3", "fs-extra": "^3.0.1", @@ -16,5 +13,9 @@ "pcap": "3.1.0", "raw-socket": "1.7.0", "ref-napi": "^3.0.3" + }, + "devDependencies": { + "shadow-cljs": "2.14.4", + "@lonocloud/dctest": "0.1.1" } } diff --git a/test/basics.yaml b/test/basics.yaml new file mode 100644 index 0000000..01ef4d1 --- /dev/null +++ b/test/basics.yaml @@ -0,0 +1,71 @@ +name: "Basic tests (DHCP, ping, mac2ip)" + +env: + DC: "${{ process.env.DOCKER_COMPOSE || 'docker compose' }}" + +tests: + dhcp: + name: "DHCP test" + env: + COMPOSE_PROFILES: dhcp + steps: + - exec: :host + run: | + ${DC} down --remove-orphans --volumes -t1 + ${DC} up -d --force-recreate + - exec: :host + run: | + echo "Waiting for compose startup" + ${DC} logs net | grep "Creating veth" + repeat: { retries: 30, interval: '2s' } + + - exec: :host + run: '[ $(${DC} logs | grep "client.*ACK from" | wc -l) -ge 4 ]' + repeat: { retries: 30, interval: '2s' } + + - exec: :host + run: ${DC} down --remove-orphans --volumes -t1 + + ping: + name: "ping test" + env: + COMPOSE_PROFILES: ping + steps: + - exec: :host + run: | + ${DC} down --remove-orphans --volumes -t1 + ${DC} up -d --force-recreate + - exec: :host + run: | + echo "Waiting for compose startup" + ${DC} logs net | grep "Creating veth" + repeat: { retries: 30, interval: '2s' } + + - exec: :host + run: '[ $(${DC} logs | grep "echo-reply" | wc -l) -ge 2 ]' + repeat: { retries: 30, interval: '2s' } + + - exec: :host + run: ${DC} down --remove-orphans --volumes -t1 + + mac2ip: + name: "mac2ipi test" + env: + COMPOSE_PROFILES: mac2ip + steps: + - exec: :host + run: | + ${DC} down --remove-orphans --volumes -t1 + ${DC} up -d --force-recreate + - exec: :host + run: | + echo "Waiting for compose startup" + ${DC} logs net | grep "Creating veth" + repeat: { retries: 30, interval: '2s' } + + - exec: :host + run: '[ $(${DC} logs | grep -o "worker-.*ACK to" | sort | uniq | wc -l) -ge 2 ]' + repeat: { retries: 30, interval: '2s' } + + - exec: :host + run: ${DC} down --remove-orphans --volumes -t1