Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Add helper script to run test from jenkins and provide jenkins job re…
Browse files Browse the repository at this point in the history
…lated information. Make waits longer to increase propability to pass bogus fails. Do not run fast-data-dev internal tests. Add README for repo.

Signed-off-by: Marios Andreopoulos <opensource@andmarios.com>
  • Loading branch information
andmarios committed Oct 7, 2016
1 parent 9bb6c6e commit 04118a9
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,8 @@
.idea
out.html
coyote.html
/results
latest.html
*-connector.properties.json
/exitcode
/status.txt
44 changes: 44 additions & 0 deletions README.md
@@ -0,0 +1,44 @@
# Connector Tests #

Basic testing of various connectors using docker and coyote.



## Prepare Test Server ##

For now we use Cloudera03 server. This will hopefully not be a permanent setup
because it gives too much rights to jenkins.
Thus instead of automating the needed steps via ansible, we will document them
here.

Permit Jenkins user to run docker and generally have some root rights by addding
it to root group:

sudo usermod -aG docker jenkins

Install docker compose via an official release since it isn't yet available in
centos.
Visit [compose github release page](https://github.com/docker/compose/releases)
for the latest release. In general, you will run something like this:

sudo su
curl -L https://github.com/docker/compose/releases/download/1.8.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

## Running in Jenkins

We have many tests which we want to run separately and in parallel. This leads
to one jenkins job per test design, which unfortunately is time-consuming to
maintain, as for each little change, we would have to update tens of jenkins'
jobs.

For this we created the `helpers` directory and there we store scripts we use
to run the tests from jenkins, thus moving the better part of the run logic to
this repo.

To run a test from Jenkins, you would run something like:

helpers/jenkins-test-runner.sh kafka-connect-redis

This runs the tests and creates such files (as status.txt and exitcode) that
the jenkins job can use to set the build name, exit status, etc.
63 changes: 63 additions & 0 deletions helpers/jenkins-test-runner.sh
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

# This script can be used by jenkins to run the tests.
# We use it to avoid having to manage too many similar jenkins jobs.
# Instead of having to apply a small change to 20 jobs, we apply it here.
#
# The only argument it takes is the test directory name.

set -e

TEST_DIR="$1"
RESULTS_DIR="results"

# Set current dir (which should be repo's top dir) to workspace so we can test
# outside jenkins
WORKSPACE="${WORKSPACE:-$(pwd)}"

# Remove old files it they exist:
rm -f "$WORKSPACE"/status.txt
rm -f "$WORKSPACE"/exitcode

# Check if test directory exists
if [[ ! -d "$1" ]]; then
echo "Test directory not found. The '\$1' argument is: $1."
exit 255
fi

# Download latest Coyote
COYOTE=coyote-1.0-amd64
wget -nc https://github.com/Landoop/coyote/releases/download/v1.0/$COYOTE
chmod +x $COYOTE

# Set path for jenkins
export PATH="$PATH:/usr/local/bin"
alias docker-compose="sudo /usr/local/bin/docker-compose"

# cd into workdir and run coyote
pushd "$TEST_DIR"
set +e
$WORKSPACE/$COYOTE
EXITCODE="$?"
set -e
popd

# Store error number for jenkins build name
if [[ $EXITCODE -eq 0 ]]; then
echo "" > "$WORKSPACE"/status.txt
elif [[ $EXITCODE -eq 1 ]]; then
echo "_${EXITCODE}_err" > "$WORKSPACE"/status.txt
else
echo "_${EXITCODE}_errs" > "$WORKSPACE"/status.txt
fi

# Store exitcode to use for output
echo "$EXITCODE" > "$WORKSPACE"/exitcode


# Copy test results to results directory
mkdir -p "$RESULTS_DIR"
DATE="$(date '+%Y%m%d-%H%M')"
cp "$TEST_DIR"/coyote.html "$RESULTS_DIR"/"$(basename ${TEST_DIR})-${DATE}$(cat status.txt).html"
rm -f latest.html
mv "$TEST_DIR"/coyote.html latest.html
4 changes: 2 additions & 2 deletions kafka-connect-redis/coyote.yml
Expand Up @@ -40,7 +40,7 @@
--data @redis-connector.properties.json
"http://localhost:58083/connectors"
stdout_not_has: [ 'HTTP/1.1 [45][0-9][0-9] ' ]
- command: sleep 20
- command: sleep 30
nolog: true

- name: Test Connector
Expand All @@ -56,7 +56,7 @@
{"firstName": "%UNIQUE_NAME1%", "lastName": "%UNIQUE_NAME2%", "age":30, "salary": 4830}
{"firstName": "%UNIQUE_NAME3%", "lastName": "%UNIQUE_NAME4%", "age":30, "salary": 3048}
timeout: 20s
- command: sleep 20
- command: sleep 60
nolog: true
- name: Verify entry 1
command: docker run --rm --net=host redis redis-cli -h 127.0.0.1 -p 56379 -a pass get "person_redis|0|0"
Expand Down
1 change: 1 addition & 0 deletions kafka-connect-redis/docker-compose.yml
Expand Up @@ -19,6 +19,7 @@ services:
- REST_PORT=58082
- CONNECT_PORT=58083
- WEB_PORT=53030
- RUNTESTS=0
redis:
image: redis
volumes:
Expand Down

0 comments on commit 04118a9

Please sign in to comment.