Skip to content

Commit

Permalink
Merge pull request #10 from idealo/improved_upsert
Browse files Browse the repository at this point in the history
fix: running upsert test on the half of the given docs
  • Loading branch information
manuelkasiske4idealo authored Nov 11, 2024
2 parents 75ee6c8 + 3ef49f2 commit f50ebfe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func main() {

collection := client.Database("benchmarking").Collection("testdata")

if testType == "insert" {
if testType == "insert" || testType == "upsert" {
if err := collection.Drop(context.Background()); err != nil {
log.Fatalf("Failed to drop collection: %v", err)
}
log.Println("Collection dropped. Starting new insert test...")
log.Println("Collection dropped. Starting new rate test...")
} else {
log.Printf("Starting %s test...\n", testType)
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func main() {
}

case "upsert":
docID := int64(rand.Intn(docCount))
docID := int64(rand.Intn(docCount / 2))
filter := bson.M{"_id": docID}
update := bson.M{"$set": bson.M{"updatedAt": time.Now().Unix(), "rnd": rand.Int63()}}
opts := options.Update().SetUpsert(true)
Expand Down
13 changes: 12 additions & 1 deletion mongo-bench-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ DOC_COUNT=$(mongosh 'mongodb://root:example@mongodb:27017/?authSource=admin' --q
if [ "$DOC_COUNT" -ne 0 ]; then
echo "Error: Expected 0 documents, found $DOC_COUNT"
exit 1
else
fi

# Run the upsert test
echo 'Running upsert test...'
./mongo-bench --uri mongodb://root:example@mongodb:27017 --type upsert --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" -gt 0 ]; then
echo 'All tests passed successfully.'
else
echo "Error: Expected >0 documents, found $DOC_COUNT"
exit 1
fi

0 comments on commit f50ebfe

Please sign in to comment.