Skip to content

Commit

Permalink
test: add mirroring e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
fraidev committed May 27, 2024
1 parent 61bbb7b commit dcd3df0
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 0 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,96 @@ jobs:
timeout-minutes: 5
run: cat /tmp/flv_sc.log

mirroring_smoke_test_e2e:
runs-on: ${{ matrix.os }}
needs:
- build_image
- config
strategy:
matrix:
os: [ubuntu-latest]
rust-target: [x86_64-unknown-linux-musl]
steps:
- uses: actions/checkout@v4
- name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: ${{ env.BATS_VERSION }}

# Download artifacts from development build
- name: Download artifact - fluvio
uses: actions/download-artifact@v4
with:
name: fluvio-${{ matrix.rust-target }}
path: ~/bin
- name: Download artifact - fluvio-run
uses: actions/download-artifact@v4
with:
name: fluvio-run-${{ matrix.rust-target }}
path: ~/extensions
- name: Download artifact - fluvio-test
uses: actions/download-artifact@v4
with:
name: fluvio-test-${{ matrix.rust-target }}
path: ~/extensions
- name: Download Docker Image as Artifact
uses: actions/download-artifact@v4
with:
name: infinyon-fluvio-${{ matrix.rust-target }}.tar
path: /tmp

- name: Set up Fluvio binaries
run: |
chmod +x ~/bin/fluvio
chmod +x ~/extensions/fluvio-run
chmod +x ~/extensions/fluvio-test
mkdir -p ~/.fluvio/bin
mkdir -p ~/.fluvio/extensions
mv ~/bin/fluvio ~/.fluvio/bin/fluvio
mv ~/extensions/fluvio-run ~/.fluvio/bin/fluvio-run
mv ~/extensions/fluvio-test ~/.fluvio/bin/fluvio-test
echo "~/.fluvio/bin" >> $GITHUB_PATH
- name: Print version
run: fluvio version && fluvio-test -h

- name: Load Fluvio Docker Image
run: |
ls -la /tmp
docker image load --input /tmp/infinyon-fluvio-${{ matrix.rust-target }}.tar
docker image tag infinyon/fluvio:${{ github.sha }}-${{ matrix.rust-target }} infinyon/fluvio:${{ github.sha }}
docker image ls -a
- name: Export Docker Image to tarball
run: docker image save infinyon/fluvio:${{ github.sha }} --output /tmp/infinyon-fluvio.tar
- name: Install K3d
run: |
curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | TAG=${{ env.K3D_VERSION }} bash
./k8-util/cluster/reset-k3d.sh
- name: Load image to K3d
run: |
k3d image import -k /tmp/infinyon-fluvio.tar -c fluvio
- name: Create k8 namespace
run: |
kubectl create ns fluvio-test
- name: Start edge cluster
run: fluvio cluster start --local

- name: Start home cluster in k8
timeout-minutes: 10
run: fluvio cluster start --k8 --develop --namespace fluvio-test --use-k8-port-forwarding

- name: Run Fluvio mirroring tests
run: make FLUVIO_BIN=~/.fluvio/bin/fluvio cli-fluvio-mirroring-smoke-e2e

- name: Print SC logs
if: ${{ !success() }}
timeout-minutes: 5
run: cat /tmp/flv_sc.log


# Runs tests on `tests/cli/partition_test`
partition_test:
name: Partitions Test (${{ matrix.test }} with ${{ matrix.spu }} SPUs, ${{ matrix.partitions }} Partitions and ${{ matrix.replication }} Replicas), Run Mode ${{ matrix.run-mode }}
Expand Down
3 changes: 3 additions & 0 deletions makefiles/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ cli-fluvio-read-only-smoke:
cli-fluvio-mirroring-smoke:
bats $(shell ls -1 ./tests/cli/mirroring_smoke_tests/*.bats | sort -R)

cli-fluvio-mirroring-smoke-e2e:
bats $(shell ls -1 ./tests/cli/mirroring_smoke_tests/e2e/*.bats | sort -R)

cli-smdk-smoke:
bats $(shell ls -1 ./tests/cli/smdk_smoke_tests/*.bats | sort -R)

Expand Down
108 changes: 108 additions & 0 deletions tests/cli/mirroring_smoke_tests/e2e/fluvio-core.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env bats

TEST_HELPER_DIR="$BATS_TEST_DIRNAME/../../test_helper"
export TEST_HELPER_DIR

load "$TEST_HELPER_DIR"/tools_check.bash
load "$TEST_HELPER_DIR"/fluvio_dev.bash
load "$TEST_HELPER_DIR"/bats-support/load.bash
load "$TEST_HELPER_DIR"/bats-assert/load.bash

setup_file() {
CURRENT_DATE=$(date +%Y-%m)
export CURRENT_DATE

REMOTE_NAME=user1
export REMOTE_NAME
debug_msg "Topic name: $REMOTE_NAME"

MESSAGE="$(random_string 7)"
export MESSAGE
debug_msg "$MESSAGE"

TOPIC_NAME=mirror-topic
export TOPIC_NAME
debug_msg "Topic name: $TOPIC_NAME"

REMOTE_PROFILE=local
export REMOTE_PROFILE
debug_msg "Remote profile: $REMOTE_PROFILE"

HOME_PROFILE=$($FLUVIO_BIN profile)
export HOME_PROFILE
debug_msg "Home profile: $HOME_PROFILE"
}

@test "Can register an remote cluster" {
run timeout 15s "$FLUVIO_BIN" remote register "$REMOTE_NAME"

assert_output "remote cluster \"$REMOTE_NAME\" was registered"
assert_success
}

@test "Export remote" {
run timeout 15s "$FLUVIO_BIN" remote export "$REMOTE_NAME" --file remote.json
assert_output ""
assert_success

run jq -r .home.id remote.json
assert_output "home"
assert_success

run jq -r .home.remoteId remote.json
assert_output "$REMOTE_NAME"
assert_success

run jq -r .home.publicEndpoint remote.json
assert_output --partial ":30003"
assert_success
}

@test "Can create a mirror topic" {
REMOTE_NAME=user1 echo "[\"$REMOTE_NAME\"]" > remotes.json
run timeout 15s "$FLUVIO_BIN" topic create "$TOPIC_NAME" --mirror-apply remotes.json

assert_output "topic \"$TOPIC_NAME\" created"
assert_success
}


@test "Can switch to remote cluster" {
run timeout 15s "$FLUVIO_BIN" profile switch "$REMOTE_PROFILE"
assert_output ""
assert_success
}

@test "Can connect to the home cluster" {
run timeout 15s "$FLUVIO_BIN" home connect --file remote.json

assert_output "connecting with \"home\" cluster"
assert_success
}

@test "Can produce message to mirror topic" {
sleep 5
run bash -c 'echo 1 | timeout 15s "$FLUVIO_BIN" produce "$TOPIC_NAME"'
assert_success
run bash -c 'echo a | timeout 15s "$FLUVIO_BIN" produce "$TOPIC_NAME"'
assert_success
run bash -c 'echo 2 | timeout 15s "$FLUVIO_BIN" produce "$TOPIC_NAME"'
assert_success
run bash -c 'echo b | timeout 15s "$FLUVIO_BIN" produce "$TOPIC_NAME"'
assert_success
}

@test "Can switch back to home cluster" {
run timeout 15s "$FLUVIO_BIN" profile switch "$HOME_PROFILE"
assert_output ""
assert_success
}

@test "Can consume message from mirror topic" {
sleep 5
run timeout 15s "$FLUVIO_BIN" consume "$TOPIC_NAME" -B -d

assert_output 1$'\n'a$'\n'2$'\n'b
assert_success
}

File renamed without changes.

0 comments on commit dcd3df0

Please sign in to comment.