At this time of writing TravisCI says that if you want to run a Cassandra service you have to add a cassandra service according to https://docs.travis-ci.com/user/database-setup/#cassandra:
services:but if you try to initialize cassandra you might find out that cassandra is not yet ready or running depending on timing.
- cassandra
The solution is:
- a .travis.yml file (see https://github.com/davidemoro/pytest-play-docker/blob/master/.travis.yml) with the cassandra service and a "bash travis/setup_cassandra.sh" command in before_script section
- a travis/setup_cassandra.sh (see https://github.com/davidemoro/pytest-play-docker/blob/master/travis/setup_cassandra.sh) that waits for cassandra up and running (e.g., a sleep 30, a polling loop with max retries implemented in my travis/setup_cassandra.sh script or using docker service) before cqlsh initialization commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo: required | |
services: | |
- cassandra | |
before_script: | |
- bash travis/setup_cassandra.sh | |
script: | |
- ... run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function cassandra_ready() { | |
count=0 | |
while ! cqlsh -e "describe cluster;" 2>&1 ; do | |
echo "waiting for cassandra" | |
if [ $count -gt 30 ] | |
then | |
exit | |
fi | |
(( count += 1 )) | |
sleep 1 | |
done | |
echo "cassandra is ready" | |
} | |
cassandra_ready | |
cqlsh -e "create keyspace dev with replication = {'class': 'SimpleStrategy', 'replication_factor': 1}; USE dev; create table play(code int primary key, title varchar); insert into play (code, title) values (1, 'hello!');" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- provider: play_cassandra | |
type: execute | |
connection: | |
contact_points: | |
- 127.0.0.1 | |
port: 9042 | |
auth_provider: | |
username: cassandra | |
password: cassandra | |
keyspace: dev | |
query: SELECT title from play WHERE code = 1; | |
variable: title | |
variable_expression: results[0].title | |
assertion: "'$title' == 'hello!'" |
No comments:
Post a Comment
Note: only a member of this blog may post a comment.