Skip to content

Commit 69090dc

Browse files
committed
feat: [#12] complete local functionality and persistence tests for mysql
1 parent 4b5dc4e commit 69090dc

File tree

2 files changed

+53
-234
lines changed

2 files changed

+53
-234
lines changed

.github/copilot-instructions.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ The project includes a comprehensive linting script that validates all file type
232232
- **No secrets**: Never commit SSH keys, passwords, or tokens
233233
- **Documentation**: Update docs for any infrastructure changes
234234

235+
#### End-to-End Smoke Testing
236+
237+
For verifying the functionality of the tracker from an end-user's perspective (e.g., simulating announce/scrape requests), refer to the **Smoke Testing Guide**. This guide explains how to use the official `torrust-tracker-client` tools to perform black-box testing against a running tracker instance without needing a full BitTorrent client.
238+
239+
- **Guide**: [Smoke Testing Guide](../docs/guides/smoke-testing-guide.md)
240+
- **When to use**: After a deployment (`make apply`) or to validate that all services are working together correctly.
241+
235242
### Security Guidelines
236243

237244
#### Secrets Management

docs/issues/12-use-mysql-instead-of-sqlite-by-default.md

Lines changed: 46 additions & 234 deletions
Original file line numberDiff line numberDiff line change
@@ -213,262 +213,74 @@ cd application/
213213
docker compose logs tracker
214214
```
215215

216-
3. **Local Functionality Testing**:
216+
**Expected Output**:
217217

218218
```bash
219-
# Test tracker announce functionality locally
220-
curl -v "http://localhost:7070/announce?info_hash=1234567890123456789012345678901234567890&peer_id=1234567890123456789&port=6881&uploaded=0&downloaded=0&left=1000&event=started"
221-
222-
# Connect to MySQL and verify data
223-
docker compose exec mysql mysql -u torrust -p torrust_tracker
224-
# Check if tables were created automatically by tracker
219+
# Verify tracker is running and connected to MySQL
220+
docker compose logs tracker | grep "Successfully connected to database"
225221
```
226222

227-
**Manual Database Connection Verification**:
228-
229-
To confirm the tracker could write to the database, we manually added a
230-
torrent to the whitelist via the API and then checked the database.
231-
232-
1. **Whitelist a torrent via API**:
233-
234-
```bash
235-
curl -X POST "http://127.0.0.1:1212/api/v1/whitelist/5452869be36f9f3350ccee6b4544e7e76caaadab?token=MyLocalAdminToken"
236-
```
237-
238-
2. **Verify the record in the `whitelist` table**:
239-
240-
```bash
241-
docker compose exec mysql mysql -u torrust \
242-
-pmy_super_secret_password torrust_tracker -e "SELECT * FROM whitelist;"
243-
```
244-
245-
This confirmed that the tracker was successfully connected to and could write to the MySQL database.
246-
247-
4. **Local Data Persistence Testing**:
248-
249-
```bash
250-
# Make announce request, restart services, verify data persists
251-
docker compose restart tracker
252-
docker compose restart mysql
253-
254-
# Verify data is still there
255-
docker compose exec mysql mysql -u torrust -p torrust_tracker -e "SHOW TABLES;"
256-
```
257-
258-
### Phase 2: VM Integration Testing
259-
260-
**Prerequisites**:
261-
262-
```bash
263-
# Ensure local testing environment is ready
264-
make test-prereq
265-
```
266-
267-
**VM Testing Steps**:
223+
3. **Local Data Persistence Testing**:
268224

269-
1. **Clean Deployment Test**:
225+
- **Status**: ✅ **Completed**
226+
- **Verification**: Data persists in MySQL after service restarts.
270227

271228
```bash
272-
make destroy # Clean any existing VMs
273-
make apply # Deploy with new MySQL configuration
274-
```
229+
# Restart services
230+
docker compose restart
275231
276-
2. **Service Health Check**:
277-
278-
```bash
279-
make ssh
280-
cd /home/torrust/github/torrust/torrust-tracker-demo
281-
docker compose ps # Verify all services are running
282-
docker compose logs mysql # Check MySQL startup logs
283-
docker compose logs tracker # Check tracker connection logs
232+
# Verify tables still exist in MySQL
233+
docker compose exec mysql mysql -u torrust -p<YOUR_PASSWORD> torrust_tracker -e "SHOW TABLES;"
284234
```
285235

286-
3. **Database Connectivity Test**:
236+
4. **VM Integration Testing**:
287237

288-
```bash
289-
# Connect to MySQL and verify database exists
290-
docker compose exec mysql mysql -u torrust -p torrust_tracker
291-
# Should connect successfully and show database with tracker tables
292-
```
293-
294-
4. **Functional Testing**:
238+
- **Status**: ⬜ **Pending**
239+
- **Description**: Deploy the complete stack on a local VM to test the full
240+
infrastructure integration.
295241

296242
```bash
297-
# Test tracker announce functionality
298-
curl -v "http://localhost:7070/announce?info_hash=1234567890123456789012345678901234567890&peer_id=1234567890123456789&port=6881&uploaded=0&downloaded=0&left=1000&event=started"
243+
# From the repository root
244+
make apply # Deploy VM
245+
make ssh # Connect to VM
246+
# Run smoke tests from the smoke testing guide
299247
```
300248

301-
5. **Data Persistence Test**:
302-
303-
```bash
304-
# Make announce request, restart services, verify data persists
305-
docker compose restart tracker
306-
# Check if torrent data is still in MySQL
307-
```
308-
309-
### Validation Checklist
310-
311-
- [x] **MySQL Service**:
312-
313-
- [x] MySQL container starts successfully
314-
- [x] Database `torrust_tracker` is created
315-
- [x] User `torrust` can connect with provided credentials
316-
- [x] Character set is `utf8mb4` with `utf8mb4_unicode_ci` collation
317-
318-
- [x] **Tracker Service**:
319-
320-
- [x] Tracker connects to MySQL without errors
321-
- [x] Tracker logs show successful database connection
322-
- [x] Database tables are created automatically by tracker
323-
- [x] No SQLite-related errors in logs
324-
325-
- [x] **Functional Testing**:
249+
### Phase 2: Documentation and Cleanup
326250

327-
- [x] Announce requests work correctly
328-
- [x] Data is written to MySQL tables (automatically created)
329-
- [ ] Scrape requests return correct data
330-
- [ ] Download counters increment properly
251+
**Status**: ⬜ **Pending**
331252

332-
- [x] **Integration Testing**:
253+
**Description**: Update all relevant documentation to reflect the MySQL migration and
254+
remove any outdated SQLite references.
333255

334-
- [ ] Grafana can access tracker metrics
335-
- [ ] Prometheus monitoring continues to work
336-
- [ ] Nginx proxy serves tracker API correctly
337-
338-
- [x] **Persistence Testing**:
339-
340-
- [ ] Data survives tracker service restart
341-
- [ ] Data survives MySQL service restart
342-
- [ ] Data survives complete stack restart
343-
- [ ] Database schema is maintained across restarts
344-
345-
## 🔄 Implementation Order
346-
347-
### Phase A: Service Configuration (No Breaking Changes)
348-
349-
1. Add MySQL service to `compose.yaml`
350-
2. Create MySQL initialization directory and README
351-
3. Update environment variables in `.env.production`
352-
4. Test MySQL service starts independently (local Docker Compose)
353-
354-
### Phase B: Tracker Integration (Local Testing)
355-
356-
1. Update tracker configuration in `tracker.toml`
357-
2. Add tracker environment variable overrides
358-
3. Update service dependencies
359-
4. **Test complete stack deployment locally with Docker Compose**
360-
5. Verify database tables are created automatically by tracker
361-
6. Validate announce/scrape functionality locally
362-
363-
### Phase C: VM Integration Testing
364-
365-
1. Deploy to VM using `make apply`
366-
2. Run comprehensive testing on VM environment
367-
3. Validate against all acceptance criteria
368-
4. Document any differences between local and VM environments
369-
370-
### Phase D: Documentation and Finalization
371-
372-
1. Update documentation files
373-
2. Document local vs VM testing procedures
374-
3. Create troubleshooting guide
375-
4. Document any migration notes
376-
377-
## 📁 File Change Summary
378-
379-
```text
380-
application/
381-
├── compose.yaml # Add MySQL service, update tracker deps
382-
├── .env.production # Add MySQL environment variables
383-
├── storage/
384-
│ ├── tracker/
385-
│ │ └── etc/
386-
│ │ └── tracker.toml # Update database configuration
387-
│ └── mysql/ # New directory
388-
│ └── init/ # New directory
389-
│ └── README.md # New file (documentation only)
390-
├── README.md # Update database requirements
391-
└── docs/
392-
├── production-setup.md # Add MySQL setup instructions
393-
└── deployment.md # Update deployment procedures
394-
```
395-
396-
**Note**: No SQL migration scripts needed - Torrust Tracker handles database migrations automatically.
397-
398-
## 🔍 Pre-Implementation Research
399-
400-
### Torrust Tracker MySQL Requirements
401-
402-
**Research Completed**:
403-
404-
- ✅ Torrust Tracker MySQL driver support confirmed
405-
- ✅ MySQL connection string format: `mysql://user:password@host:port/database`
406-
- ✅ Configuration uses single `path` parameter, not individual connection fields
407-
- ✅ Database migrations are handled automatically by tracker
408-
409-
**Key Findings**:
410-
411-
1. **Automatic Migrations**: Torrust Tracker handles database migrations automatically
412-
through built-in migration system in database drivers
413-
2. **Connection Format**: Uses MySQL connection string in `path` field
414-
3. **Table Creation**: Tables are created automatically on tracker startup
415-
4. **No Manual Setup**: No manual schema setup or migration scripts required
416-
417-
### Environment Variable Validation
418-
419-
**Research Tasks**:
420-
421-
- [ ] Verify exact environment variable names used by Torrust Tracker
422-
- [ ] Test environment variable override behavior with connection string format
423-
- [ ] Confirm configuration precedence (file vs environment)
424-
425-
## 🚨 Risk Assessment
426-
427-
### High Risk Items
428-
429-
- **Database connection failures**: Ensure proper networking between services
430-
- **Character set issues**: UTF-8 handling for torrent names and peer data
431-
- **Environment variable conflicts**: Ensure no conflicting configurations
432-
433-
### Medium Risk Items
434-
435-
- **Performance differences**: MySQL vs SQLite performance characteristics
436-
- **Volume permissions**: Ensure MySQL data directory has correct permissions
437-
- **Service startup timing**: MySQL must be ready before tracker starts
438-
439-
### Low Risk Items
440-
441-
- **Documentation gaps**: Missing or unclear setup instructions
442-
- **Development environment differences**: Local vs production environment parity
443-
444-
## 🎯 Success Criteria
445-
446-
### Must Have
256+
**Files to Update**:
447257

448-
- [ ] MySQL service starts and is accessible
449-
- [ ] Tracker connects to MySQL successfully
450-
- [ ] Basic announce/scrape functionality works
451-
- [ ] Data persists across service restarts
452-
- [ ] All existing functionality continues to work
258+
- `application/README.md`
259+
- `application/docs/production-setup.md`
260+
- `docs/guides/smoke-testing-guide.md` (if it contains database-specific instructions)
261+
- `.github/copilot-instructions.md` (ensure it reflects current best practices)
453262

454-
### Should Have
263+
## ✅ Completion Checklist
455264

456-
- [ ] Performance is equivalent to SQLite
457-
- [ ] Comprehensive documentation is updated
458-
- [ ] Migration path from SQLite is documented
459-
- [ ] Local testing environment works reliably
265+
- [x] MySQL service added to `compose.yaml`
266+
- [x] Environment variables configured in `.env.production`
267+
- [x] Tracker `tracker.toml` defaults to MySQL
268+
- [x] MySQL initialization directory documented
269+
- [x] Docker Compose service dependencies updated
270+
- [x] Local functionality testing passed
271+
- [x] Local data persistence testing passed
272+
- [ ] VM integration testing passed
273+
- [ ] All documentation updated
274+
- [ ] Old SQLite configurations removed or documented as legacy
275+
- [ ] Final PR reviewed and approved
460276

461-
### Nice to Have
277+
## Rollback Plan
462278

463-
- [ ] Database monitoring via Grafana
464-
- [ ] Automated database backup considerations
465-
- [ ] Performance optimization notes
279+
If critical issues arise, the following steps can be taken to revert to SQLite:
466280

467-
## 📚 References
281+
1. **Revert `compose.yaml`**: Remove the MySQL service and dependencies.
282+
2. **Revert `.env.production`**: Restore SQLite environment variables.
283+
3. **Revert `tracker.toml`**: Set the database driver back to `sqlite3`.
284+
4. **Restart Services**: Run `docker compose up -d --force-recreate`.
468285

469-
- [Torrust Tracker Documentation](https://docs.rs/torrust-tracker/)
470-
- [Torrust Tracker MySQL Configuration Example](https://github.com/torrust/torrust-tracker/blob/develop/share/default/config/tracker.container.mysql.toml)
471-
- [Torrust Tracker MySQL Driver Source](https://github.com/torrust/torrust-tracker/blob/develop/packages/tracker-core/src/databases/driver/mysql.rs)
472-
- [MySQL 8.0 Documentation](https://dev.mysql.com/doc/refman/8.0/en/)
473-
- [Docker Compose Networking](https://docs.docker.com/compose/networking/)
474-
- [Migration Plan](../plans/hetzner-migration-plan.md)
286+
This ensures a quick rollback path if the MySQL integration causes unforeseen problems.

0 commit comments

Comments
 (0)