Skip to content

Commit

Permalink
Refactor itests to allow adding multiple transport sinks (#28)
Browse files Browse the repository at this point in the history
* Refactor itests to be allow adding multiple transport sinks

* split out tests into base & transport

* organize all base tests together

* yaml lint

* unset context after test
  • Loading branch information
nehalrp authored Apr 23, 2019
1 parent ad0fff4 commit c532ac1
Show file tree
Hide file tree
Showing 96 changed files with 153 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ step_library:
command: |
git submodule sync
git submodule update --init || (rm -fr .git/config .git/modules && git submodule deinit -f . && git submodule update --init)
make itests-circleci
make itests
- &step_build_artifact
run:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ _vendor-*/
target/

# exclude itest outputs
itests/tests/*/output/*
itests/tests/*/*/output/*
itests/test_output/*
itests/tests/*/*/perf_output/*
itests/perf_output/*
8 changes: 1 addition & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,9 @@ test: vendor generate vet
@echo "Executing tests ..."
go test -race -v ${GO_TEST_EXTRAS} ./...

itests-circleci:
@echo "Running integration tests"
TEST_NAME=test_basic docker-compose -f itests/docker-compose.yml build
cd ./itests && ./circleci_split_itests.sh

itests:
@echo "Running integration tests"
TEST_NAME=test_basic docker-compose -f itests/docker-compose.yml build
cd ./itests && ./integration_tests.bats -r tests
cd ./itests && ./itests_runner.sh

clean:
@echo "Removing vendor deps"
Expand Down
23 changes: 0 additions & 23 deletions itests/circleci_split_itests.sh

This file was deleted.

4 changes: 2 additions & 2 deletions itests/common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ _startup() {
sleep 5

_check_container postgres
_check_container kinesis
_check_container localstack
_check_container bifrost

log "Containers are running!"
Expand Down Expand Up @@ -221,7 +221,7 @@ _profile() {

_wait() {
log "Waiting for test to finish"
grep -q 'Records read' <(docker logs --follow kinesis-poller 2>&1)
grep -q 'Records read' <(docker logs --follow data-poller 2>&1)
pkill -f "docker logs.*" || true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ RUN \

ADD app /app
VOLUME /output
CMD ["python", "/app/poller.py"]
CMD ["sh", "/app/entrypoint.sh"]
6 changes: 6 additions & 0 deletions itests/containers/data-poller/app/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

# Please set this in your docker run config to specify which poller is used.
TRANSPORT_SINK=${TRANSPORT_SINK:-}

python /app/poller-$TRANSPORT_SINK.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Variables
OUT_FILE = os.getenv('OUT_FILE', '/output/test')
STREAM_NAME = os.getenv('STREAM_NAME', 'itests')
ENDPOINT_URL = os.getenv('ENDPOINT_URL', 'http://kinesis:4568')
ENDPOINT_URL = os.getenv('ENDPOINT_URL', 'http://localstack:4568')
WAIT_TIME = int(os.getenv('WAIT_TIME', '90'))
EXPECTED_COUNT = int(os.getenv('EXPECTED_COUNT', '1'))
AWS_REGION = os.getenv('AWS_REGION', 'us-east-1')
Expand Down
1 change: 0 additions & 1 deletion itests/containers/defaults.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ BIFROST_KINESIS_STREAM=itests
AWS_ACCESS_KEY_ID=DUMMYACCESSKEYID
AWS_SECRET_ACCESS_KEY=DUMMYSECRETACCESSKEY
AWS_REGION=us-east-1
ENDPOINT=http://kinesis:4568
3 changes: 3 additions & 0 deletions itests/contexts/kinesis.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TRANSPORT_SINK=kinesis
LOCALSTACK_PORT=4568
ENDPOINT=http://localstack:4568
38 changes: 20 additions & 18 deletions itests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ services:
networks:
- net

kinesis:
container_name: kinesis
localstack:
container_name: localstack
image: localstack/localstack:0.8.7
env_file:
- "./containers/defaults.env"
- "./tests/${TEST_NAME}/envfile.env"
- "./containers/defaults.env"
- "./tests/${TEST_NAME}/envfile.env"
environment:
- SERVICES=kinesis
- SERVICES=${TRANSPORT_SINK}
ports:
- 4568:4568
- ${LOCALSTACK_PORT}:${LOCALSTACK_PORT}
restart: always
networks:
- net
Expand All @@ -28,29 +28,31 @@ services:
container_name: bifrost
image: pg-bifrost:latest
env_file:
- "./containers/defaults.env"
- "./tests/${TEST_NAME}/envfile.env"
- "./containers/defaults.env"
- "./tests/${TEST_NAME}/envfile.env"
- "./contexts/${TRANSPORT_SINK}.env"
volumes:
- "./tests/${TEST_NAME}/perf_output:/perf"
networks:
net:
aliases:
- kinesis
- localstack
- postgres
command: /pg-bifrost replicate kinesis
command: /pg-bifrost replicate ${TRANSPORT_SINK}

kinesis-poller:
container_name: kinesis-poller
build: containers/kinesis-poller
data-poller:
container_name: data-poller
build: containers/data-poller
env_file:
- "./containers/defaults.env"
- "./tests/${TEST_NAME}/envfile.env"
- "./containers/defaults.env"
- "./tests/${TEST_NAME}/envfile.env"
- "./contexts/${TRANSPORT_SINK}.env"
volumes:
- "./tests/${TEST_NAME}/output:/output"
- "./tests/${TEST_NAME}/output:/output"
networks:
net:
aliases:
- kinesis
- localstack

networks:
net:
net:
46 changes: 46 additions & 0 deletions itests/itests_runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

# Copyright 2019 Nextdoor.com, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

get_testfiles() {
_transport_sink=$1

if [ "$CI" == "true" ]; then
_base_testfiles=$(cd tests/base && circleci tests glob "*" | circleci tests split --split-by=timings | sed -e 's/^/base\//')
_specific_testfiles=$(cd tests/${_transport_sink} && circleci tests glob "*" | circleci tests split --split-by=timings | sed -e "s/^/${_transport_sink}\//")
else
_base_testfiles=$(cd tests/base && ls -d */ | sed 's#/##' | sed -e 's/^/base\//')
_specific_testfiles=$(cd tests/${_transport_sink} && ls -d */ | sed 's#/##' | sed -e "s/^/${_transport_sink}\//")
fi

echo "${_base_testfiles} ${_specific_testfiles}"
}

# Kinesis
set -a ; . contexts/kinesis.env ; set +a

TEST_NAME=base/test_basic docker-compose -f docker-compose.yml build
TESTFILES=$(get_testfiles $TRANSPORT_SINK)

echo "TESTFILES:"
echo $TESTFILES | tr ' ' '\n'

for TEST in $TESTFILES
do
echo "running test $TEST"
./integration_tests.bats -r tests -f "$TEST"
done

unset $(cat contexts/kinesis.env | awk -F= '{print $1}' | xargs)
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions itests/tests/base/test_basic/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load ../../../common

@test "base/test_basic" {
do_test
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions itests/tests/base/test_blacklist/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load ../../../common

@test "base/test_blacklist" {
do_test
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions itests/tests/base/test_large_sleep/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load ../../../common

@test "base/test_large_sleep" {
do_test
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions itests/tests/base/test_large_txn/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load ../../../common

@test "base/test_large_txn" {
do_test
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions itests/tests/base/test_small_queue/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load ../../../common

@test "base/test_small_queue" {
do_test
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions itests/tests/base/test_staggered/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load ../../../common

@test "base/test_staggered" {
do_test
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions itests/tests/base/test_timeout/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load ../../../common

@test "base/test_timeout" {
do_test
}
5 changes: 5 additions & 0 deletions itests/tests/base/test_txn_shard_partition/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load ../../../common

@test "base/test_txn_shard_partition" {
do_test
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions itests/tests/base/test_whitelist/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load ../../../common

@test "base/test_whitelist" {
do_test
}
5 changes: 5 additions & 0 deletions itests/tests/kinesis/test_high_kinesis_errors/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load ../../../common

@test "kinesis/test_high_kinesis_errors" {
do_test
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load ../../../common

@test "kinesis/test_multi_worker_high_kinesis_errors" {
do_test
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load ../../../common

@test "kinesis/test_multi_worker_no_kinesis_errors" {
do_test
}
5 changes: 5 additions & 0 deletions itests/tests/kinesis/test_strict_order_shared/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load ../../../common

@test "kinesis/test_strict_order_shared" {
SORT=false do_test
}
5 changes: 5 additions & 0 deletions itests/tests/kinesis/test_table_partitioning/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load ../../../common

@test "kinesis/test_table_partitioning" {
do_test
}
5 changes: 0 additions & 5 deletions itests/tests/test_basic/test.bats

This file was deleted.

5 changes: 0 additions & 5 deletions itests/tests/test_blacklist/test.bats

This file was deleted.

5 changes: 0 additions & 5 deletions itests/tests/test_high_kinesis_errors/test.bats

This file was deleted.

5 changes: 0 additions & 5 deletions itests/tests/test_large_sleep/test.bats

This file was deleted.

5 changes: 0 additions & 5 deletions itests/tests/test_large_txn/test.bats

This file was deleted.

5 changes: 0 additions & 5 deletions itests/tests/test_multi_worker_high_kinesis_errors/test.bats

This file was deleted.

5 changes: 0 additions & 5 deletions itests/tests/test_multi_worker_no_kinesis_errors/test.bats

This file was deleted.

5 changes: 0 additions & 5 deletions itests/tests/test_small_queue/test.bats

This file was deleted.

5 changes: 0 additions & 5 deletions itests/tests/test_staggered/test.bats

This file was deleted.

5 changes: 0 additions & 5 deletions itests/tests/test_strict_order_shared/test.bats

This file was deleted.

5 changes: 0 additions & 5 deletions itests/tests/test_table_partitioning/test.bats

This file was deleted.

Loading

0 comments on commit c532ac1

Please sign in to comment.