-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from idealo/fix_delete_test
fix: guaranteed that all documents were deleted
- Loading branch information
Showing
5 changed files
with
141 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
FROM golang:1.22 AS builder | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY . . | ||
|
||
RUN go build -o mongo-bench | ||
|
||
FROM ubuntu:jammy | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder /app/mongo-bench /app/mongo-bench | ||
COPY --from=builder /app/mongo-bench-entrypoint.sh /app/mongo-bench-entrypoint.sh | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y netcat-openbsd wget gnupg jq && \ | ||
wget -qO- https://www.mongodb.org/static/pgp/server-8.0.asc | tee /etc/apt/trusted.gpg.d/server-8.0.asc && \ | ||
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-8.0.list | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y mongodb-mongosh | ||
|
||
ENTRYPOINT ["/app/mongo-bench"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
version: '3.8' | ||
|
||
services: | ||
mongodb: | ||
image: mongo:latest | ||
container_name: mongodb | ||
ports: | ||
- "27017:27017" | ||
environment: | ||
MONGO_INITDB_ROOT_USERNAME: root | ||
MONGO_INITDB_ROOT_PASSWORD: example | ||
networks: | ||
- mongo-network | ||
|
||
mongo-bench: | ||
build: | ||
context: . | ||
container_name: mongo-bench | ||
depends_on: | ||
- mongodb | ||
networks: | ||
- mongo-network | ||
entrypoint: ["/app/mongo-bench-entrypoint.sh"] | ||
|
||
|
||
|
||
networks: | ||
mongo-network: | ||
driver: bridge |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module benchmarking | ||
|
||
go 1.22.4 | ||
go 1.22 | ||
|
||
require go.mongodb.org/mongo-driver v1.17.1 | ||
|
||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
# Wait for MongoDB to be ready | ||
until nc -z mongodb 27017; do | ||
echo 'Waiting for MongoDB...' | ||
sleep 2 | ||
done | ||
|
||
# Run the insert test | ||
echo 'Running insert test...' | ||
./mongo-bench --uri mongodb://root:example@mongodb:27017 --type insert --threads 10 --docs 80000 | ||
|
||
# Check the document count and verify it's 1000 | ||
echo 'Checking document count...' | ||
DOC_COUNT=$(mongosh 'mongodb://root:example@mongodb:27017/?authSource=admin' --quiet --eval 'JSON.stringify({count: db.getSiblingDB("benchmarking").testdata.countDocuments()})' | jq -r '.count') | ||
|
||
if [ -z "$DOC_COUNT" ]; then | ||
echo 'Error: Failed to retrieve document count.' | ||
exit 1 | ||
elif [ "$DOC_COUNT" -ne 80000 ]; then | ||
echo "Error: Expected 80000 documents, found $DOC_COUNT" | ||
exit 1 | ||
fi | ||
|
||
# Run the delete test | ||
echo 'Running delete test...' | ||
./mongo-bench --uri mongodb://root:example@mongodb:27017 --type delete --threads 10 --docs 80000 | ||
|
||
echo 'Checking document count...' | ||
DOC_COUNT=$(mongosh 'mongodb://root:example@mongodb:27017/?authSource=admin' --quiet --eval 'JSON.stringify({count: db.getSiblingDB("benchmarking").testdata.countDocuments()})' | jq -r '.count') | ||
if [ "$DOC_COUNT" -ne 0 ]; then | ||
echo "Error: Expected 0 documents, found $DOC_COUNT" | ||
exit 1 | ||
else | ||
echo 'All tests passed successfully.' | ||
fi |