-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5930: Enable running tests locally using Docker #1920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ajcvickers
wants to merge
4
commits into
mongodb:main
Choose a base branch
from
ajcvickers:Tests_3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
715d52b
CSHARP-5930: Enable SmoteTests and Driver.Examples running locally
ajcvickers d62e1c1
Tweak cluster conditions
ajcvickers 699b7db
Use DirectConnection to enable tests explicitly connecting to a repli…
ajcvickers 73e25b0
Updates to run against non-Atlas docker.
ajcvickers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,35 @@ | ||
| services: | ||
| mongodb: | ||
| image: mongo:8 | ||
| container_name: mongodb-test | ||
| command: > | ||
| mongod | ||
| --replSet rs0 | ||
| --bind_ip_all | ||
| --setParameter enableTestCommands=1 | ||
| ports: | ||
| - "56665:27017" | ||
| volumes: | ||
| - mongodb_data:/data/db | ||
| healthcheck: | ||
| test: | | ||
| mongosh --quiet --eval " | ||
| try { | ||
| rs.status(); | ||
| print('Replica set initialized'); | ||
| } catch(e) { | ||
| print('Initializing replica set...'); | ||
| rs.initiate({ | ||
| _id: 'rs0', | ||
| members: [{ _id: 0, host: 'localhost:27017' }] | ||
| }); | ||
| } | ||
| " | ||
| interval: 5s | ||
| timeout: 10s | ||
| retries: 10 | ||
| start_period: 10s | ||
|
|
||
| volumes: | ||
| mongodb_data: | ||
| driver: local |
This file contains hidden or 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 hidden or 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,102 @@ | ||
| #!/bin/bash | ||
|
|
||
| # MongoDB Test Environment Startup Script | ||
| # Starts MongoDB with single-node replica set and test commands enabled | ||
|
|
||
| set -e | ||
|
|
||
| # Colors for output | ||
| RED='\033[0;31m' | ||
| GREEN='\033[0;32m' | ||
| YELLOW='\033[1;33m' | ||
| BLUE='\033[0;34m' | ||
| NC='\033[0m' # No Color | ||
|
|
||
| # Function to print colored messages | ||
| print_info() { | ||
| echo -e "${BLUE}[INFO]${NC} $1" | ||
| } | ||
|
|
||
| print_success() { | ||
| echo -e "${GREEN}[SUCCESS]${NC} $1" | ||
| } | ||
|
|
||
| print_warning() { | ||
| echo -e "${YELLOW}[WARNING]${NC} $1" | ||
| } | ||
|
|
||
| print_error() { | ||
| echo -e "${RED}[ERROR]${NC} $1" | ||
| } | ||
|
|
||
| # Check if Docker is installed | ||
| if ! command -v docker &> /dev/null; then | ||
| print_error "Docker is not installed. Please install Docker first." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if Docker Compose is available | ||
| if ! docker compose version &> /dev/null; then | ||
| print_error "Docker Compose is not available. Please install Docker Compose." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if docker-compose.yml exists | ||
| if [ ! -f "docker-compose.yml" ]; then | ||
| print_error "docker-compose.yml not found in current directory." | ||
| exit 1 | ||
| fi | ||
|
|
||
| print_info "Starting MongoDB with test commands enabled..." | ||
|
|
||
| # Stop any existing containers | ||
| docker compose down 2>/dev/null || true | ||
|
|
||
| # Start MongoDB | ||
| docker compose up -d | ||
|
|
||
| print_info "Waiting for MongoDB to be ready..." | ||
|
|
||
| # Wait for container to be healthy | ||
| max_attempts=30 | ||
| attempt=0 | ||
| while [ $attempt -lt $max_attempts ]; do | ||
| if docker compose ps | grep -q "healthy"; then | ||
| print_success "MongoDB is ready!" | ||
| break | ||
| fi | ||
|
|
||
| attempt=$((attempt + 1)) | ||
| if [ $attempt -eq $max_attempts ]; then | ||
| print_error "MongoDB failed to start within expected time." | ||
| print_info "Showing container logs:" | ||
| docker compose logs | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo -n "." | ||
| sleep 2 | ||
| done | ||
|
|
||
| echo "" | ||
|
|
||
| # Display connection information | ||
| print_success "MongoDB is running with the following configuration:" | ||
| echo "" | ||
| echo " • Single-node replica set: rs0" | ||
| echo " • Test commands: ENABLED" | ||
| echo " • Port: 56665" | ||
| echo "" | ||
| echo "Connection String:" | ||
| echo " mongodb://localhost:56665/?replicaSet=rs0&directConnection=true" | ||
| echo "" | ||
| echo "C# Driver Connection String:" | ||
| echo ' var connectionString = "mongodb://localhost:56665/?replicaSet=rs0&directConnection=true";' | ||
| echo ' var client = new MongoClient(connectionString);' | ||
| echo "" | ||
| print_info "To stop MongoDB, run:" | ||
| echo " docker compose down" | ||
| echo "" | ||
| print_info "To view logs, run:" | ||
| echo " docker compose logs -f" | ||
| echo "" |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.