Browse the Repo

file-type-icon.circleci
file-type-iconexamples
file-type-iconmodules
file-type-icontest
file-type-iconGopkg.lock
file-type-iconGopkg.toml
file-type-iconREADME.md
file-type-iconopen_jdk_test.go
file-type-iconzookeeper_cluster_test.go
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-icon.pre-commit-hooks.yaml
file-type-iconCODEOWNERS
file-type-iconLICENSE.txt
file-type-iconREADME.md

Browse the Repo

file-type-icon.circleci
file-type-iconexamples
file-type-iconmodules
file-type-icontest
file-type-iconGopkg.lock
file-type-iconGopkg.toml
file-type-iconREADME.md
file-type-iconopen_jdk_test.go
file-type-iconzookeeper_cluster_test.go
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-icon.pre-commit-hooks.yaml
file-type-iconCODEOWNERS
file-type-iconLICENSE.txt
file-type-iconREADME.md
Apache ZooKeeper

Apache ZooKeeper

Deploy an Apache ZooKeeper cluster. Supports automatic bootstrap, Exhibitor, zero-downtime rolling deployment, and auto healing.

Code Preview

Preview the Code

mobile file icon

README.md

down

Tests

This folder contains the tests for the modules in this repo.

Running the tests locally

Running Services With Docker

Build AMIs and launching EC2 Instances can take a long time, making local development cycles painfully slow. For that reason, this repo has enabled Docker-based tests that will launch a service using Docker and docker-compose to support much faster cycles times. See Terratest Best Practices for additional detail.

How To Run Docker Tests

To run your "unit tests" with Docker manually:

cd examples/zookeeper-cluster

# Pick one of the following
export OS_NAME="ubuntu"
export OS_NAME="centos"
export OS_NAME="amazon-linux"

docker-compose up

To run "unit tests" with Docker automatically:

cd test

# To run all Linux distros
go test -run TestUnitZooKeeper*

# To run a single Linux disro
go test -run TestUnitZooKeeperUbuntu
go test -run TestUnitZooKeeperCentos
go test -run TestUnitZooKeeperAmazonLinux
  1. Run the main tests

    Now we're ready to run the main tests. Note that we'll tell Terratest to skip building an AMI, and calling terraform apply by setting the appropriate env vars:

    # To run just the Unbuntu test
    env SKIP_setup_ami=true SKIP_setup_deploy=true SKIP_validate_redeploy=true SKIP_teardown_terraform=true SKIP_teardown_test_data=true go test -run TestZooKeeperClusterUbuntu
    
    # To run all tests
    env SKIP_setup_ami=true SKIP_setup_deploy=true SKIP_validate_redeploy=true SKIP_teardown_terraform=true SKIP_teardown_test_data=true go test
    

Gotchas

  1. When tests are run repeatedly on the same Zookeeper cluster, they cause the following error Connect to ZooKeeper returned an error: zk: node already exists. I did not invest time to fix this because you can easily launch a new test cluster with docker-compose stop && docker-compose rm, and it seemed likely to be a test code error rather than a Zookeeper error.

Running Full Tests Locally

Note #1: Many of these tests create real resources in an AWS account. That means they cost money to run, especially if you don't clean up after yourself. Please be considerate of the resources you create and take extra care to clean everything up when you're done!

Note #2: Never hit CTRL + C or cancel a build once tests are running or the cleanup tasks won't run!

Note #3: We set -timeout 45m on all tests not because they necessarily take 45 minutes, but because Go has a default test timeout of 10 minutes, after which it does a SIGQUIT, preventing the tests from properly cleaning up after themselves. Therefore, we set a timeout of 45 minutes to make sure all tests have enough time to finish and cleanup.

Prerequisites

  • Install the latest version of Go.
  • Install glide for Go dependency management. On OSX, the simplest way to install is brew update; brew install glide.
  • Install Terraform.
  • Add your AWS credentials as environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
  • For some of the tests, you also need to set the GITHUB_OAUTH_TOKEN environment variable to a valid GitHub auth token with "repo" access. You can generate one here: https://github.com/settings/tokens

Setup

Download Go dependencies using Godep:

cd test
dep ensure

Run all the tests

cd test
go test -v -timeout 45m -parallel 128

Run a specific test

To run a specific test called TestFoo:

cd test
go test -v -timeout 45m -parallel 128 -run TestFoo

Questions? Ask away.

We're here to talk about our services, answer any questions, give advice, or just to chat.

Ready to hand off the Gruntwork?