From 5fca44ca45b485896a61c60b7161ecc58f82cc48 Mon Sep 17 00:00:00 2001 From: Felipe Cardozo Date: Mon, 9 Dec 2024 22:47:03 -0300 Subject: [PATCH] test: backoff and retry on failure --- tests/auto-offset-management.bats | 67 ++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 9 deletions(-) diff --git a/tests/auto-offset-management.bats b/tests/auto-offset-management.bats index dd25108..c6692ff 100644 --- a/tests/auto-offset-management.bats +++ b/tests/auto-offset-management.bats @@ -5,6 +5,10 @@ load './bats-helpers/bats-assert/load' load './bats-helpers/tools_check.bash' setup_file() { + CDK_BIN=${CDK_BIN:-cdk} + export CDK_BIN + FLUVIO_BIN=${FLUVIO_BIN:-fluvio} + export FLUVIO_BIN TEST_DIR="$(mktemp -d -t auto-offset-mngt-test.XXXXX)" export TEST_DIR } @@ -20,7 +24,7 @@ setup() { ./target/debug/tiny-http-server & disown MOCK_PID=$! - fluvio topic create $TOPIC + $FLUVIO_BIN topic create $TOPIC } @test "Read stream from the beginning" { @@ -44,10 +48,10 @@ http: interval: 3s EOF - echo "RecordOne" | fluvio produce $TOPIC - echo "RecordTwo" | fluvio produce $TOPIC + echo "RecordOne" | $FLUVIO_BIN produce $TOPIC + echo "RecordTwo" | $FLUVIO_BIN produce $TOPIC - cdk deploy -p http-sink start --config $CONFIG_PATH --log-level info + $CDK_BIN deploy -p http-sink start --config $CONFIG_PATH --log-level info wait_for_line_in_file "monitoring started" $LOG_PATH 30 @@ -75,23 +79,68 @@ http: interval: 3s EOF - cdk deploy -p http-sink start --config $CONFIG_PATH --log-level info + $CDK_BIN deploy -p http-sink start --config $CONFIG_PATH --log-level info wait_for_line_in_file "monitoring started" $LOG_PATH 30 - echo "RecordOne" | fluvio produce $TOPIC + echo "RecordOne" | $FLUVIO_BIN produce $TOPIC sleep 15 - echo "RecordTwo" | fluvio produce $TOPIC + echo "RecordTwo" | $FLUVIO_BIN produce $TOPIC wait_for_line_in_file "RecordOne" $LOGGER_FILENAME 30 wait_for_line_in_file "RecordTwo" $LOGGER_FILENAME 30 - OFFSET=$(fluvio consumer list -O json | jq ".[] | select(.consumer_id == \"$CONNECTOR_NAME\") | .offset") + OFFSET=$($FLUVIO_BIN consumer list -O json | jq ".[] | select(.consumer_id == \"$CONNECTOR_NAME\") | .offset") assert [ ! -z $OFFSET ] } +@test "Backoff and retry on failure" { + CONFIG_PATH="$TEST_DIR/$TOPIC.yaml" + cat <$CONFIG_PATH +apiVersion: 0.2.0 +meta: + version: 0.1.0 + name: $CONNECTOR_NAME + type: http-sink + topic: + meta: + name: $TOPIC + consumer: + id: $CONNECTOR_NAME + offset: + strategy: auto + start: beginning +http: + endpoint: http://localhost:8080 + interval: 3s +EOF + + echo "RecordOne" | $FLUVIO_BIN produce $TOPIC + echo "RecordTwo" | $FLUVIO_BIN produce $TOPIC + + $CDK_BIN deploy -p http-sink start --config $CONFIG_PATH --log-level info + + wait_for_line_in_file "monitoring started" $LOG_PATH 30 + + wait_for_line_in_file "RecordOne" $LOGGER_FILENAME 30 + wait_for_line_in_file "RecordTwo" $LOGGER_FILENAME 30 + + kill $MOCK_PID + + echo "RecordThree" | $FLUVIO_BIN produce $TOPIC + echo "RecordFour" | $FLUVIO_BIN produce $TOPIC + + sleep 20 + + ./target/debug/tiny-http-server & disown + MOCK_PID=$! + + wait_for_line_in_file "RecordThree" $LOGGER_FILENAME 30 + wait_for_line_in_file "RecordFour" $LOGGER_FILENAME 30 +} + teardown() { - cdk deploy shutdown --name $CONNECTOR_NAME + $CDK_BIN deploy shutdown --name $CONNECTOR_NAME kill $MOCK_PID }