Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ FROM golang:1.10-stretch
WORKDIR /go/src/github.com/percona/mongodb-backup
COPY . .

RUN go get ./...
CMD go test -v ./...
RUN go get -v ./...

USER nobody
CMD GOCACHE=off go test -race -coverprofile=/tmp/cover.out -covermode=atomic -v ./...
22 changes: 18 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@ version: '3'
services:
mongo:
image: percona/percona-server-mongodb:${TEST_PSMDB_VERSION:-latest}
command: --replSet=${TEST_PSMDB_RSNAME:-rs} --bind_ip=0.0.0.0 --bind_ip_all
expose:
- 27017
- "27017"
init:
image: percona/percona-server-mongodb:${TEST_PSMDB_VERSION:-latest}
entrypoint: /init-replset.sh
volumes:
- ./test/init-replset.sh:/init-replset.sh
environment:
- TEST_MONGODB_URI=mongo:27017
- TEST_PSMDB_RSNAME=${TEST_PSMDB_RSNAME:-rs}
links:
- mongo
depends_on:
- mongo
test:
build:
dockerfile: Dockerfile.test
context: .
environment:
- TEST_MONGODB_URI=mongo:27017
- TEST_MONGODB_URI=mongo:27017
links:
- mongo
- mongo
depends_on:
- mongo
- init
- mongo
7 changes: 5 additions & 2 deletions internal/oplog/oplog_tail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ func init() {
}

// get db uri from environment if it exists
dbUri := strings.TrimSpace(os.Getenv(EnvDBUri))
if dbUri == "" {
dbUri = strings.TrimSpace(os.Getenv(EnvDBUri))
if dbUri != "" {
fmt.Printf("Using mongodb uri from environment: %s\n", dbUri)
} else {
dbUri = dbDefaultUri
fmt.Printf("Using default mongodb uri: %s\n", dbUri)
}

if testing.Verbose() {
Expand Down
41 changes: 41 additions & 0 deletions test/init-replset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

tries=1
max_tries=15
sleep_secs=5

sleep $sleep_secs
while [ $tries -lt $max_tries ]; do
/usr/bin/mongo --quiet \
--host ${TEST_MONGODB_URI} \
--eval 'rs.initiate({
_id: "'${TEST_PSMDB_RSNAME}'",
version: 1,
members: [
{ _id: 0, host: "'${TEST_MONGODB_URI}'" }
]})'
[ $? == 0 ] && break
echo "# INFO: retrying rs.initiate() in $sleep_secs secs (try $tries/$max_tries)"
sleep $sleep_secs
tries=$(($tries + 1))
done
if [ $tries -ge $max_tries ]; then
echo "# ERROR: reached max tries $max_tries, exiting"
exit 1
fi

sleep $sleep_secs
tries=1
while [ $tries -lt $max_tries ]; do
ISMASTER=$(/usr/bin/mongo --quiet \
--host ${TEST_MONGODB_URI} \
--eval 'printjson(db.isMaster().ismaster)' 2>/dev/null)
[ "$ISMASTER" == "true" ] && break
echo "# INFO: retrying db.isMaster() check in $sleep_secs secs (try $tries/$max_tries)"
sleep $sleep_secs
tries=$(($tries + 1))
done
if [ $tries -ge $max_tries ]; then
echo "# ERROR: reached max tries $max_tries, exiting"
exit 1
fi