Spaces:
Sleeping
Sleeping
File size: 11,867 Bytes
2fe2727 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | # π PRODUCTION READINESS TESTING GUIDE
**Status**: Before deployment to HuggingFace Spaces
**Time Required**: 3 hours
**Tools Needed**: Browser, Python 3.7+, requests library
---
## π WHAT'S CHANGED
### Added: Comprehensive Production Logging
- Every API endpoint now logs:
- Operation start/end
- Success/failure status
- Input parameters (paths, filenames)
- Execution time
- Exceptions with stack traces
**Example log output**:
```
[UPLOAD_FILE] START | user=default_user | file=document.pdf | folder=reports | size=1048576
[UPLOAD_FILE] SUCCESS | user=default_user | file=document.pdf | folder=reports
[RENAME] START | user=default_user | path=reports | new_name=archive_reports
[RENAME] SUCCESS | user=default_user | old_path=reports | new_name=archive_reports
```
### Added: Automated Stress Test Script
`stress_test.py` - Runs 5 comprehensive stress tests:
1. Bulk Upload (50 files)
2. Folder Rename with 30 files
3. Rapid Operations (uploadβdeleteβrename)
4. Cache Behavior (TTL validation)
5. Error Handling (invalid operations)
---
## π§ͺ TESTING EXECUTION PLAN
### PHASE 1: Setup (15 minutes)
#### Step 1: Verify Logging
```bash
# Check that logging is configured correctly
cd c:\Users\mohat\OneDrive\Desktop\Doc
python -c "from server.utils.logger import setup_logger; logger = setup_logger('test'); logger.info('Logging works')"
```
Expected output: Should see log message in console or logs/ directory
#### Step 2: Install Test Dependencies
```bash
pip install requests
```
---
### PHASE 2: Manual Testing (45 minutes)
#### Test A: Basic Rename (NEW FEATURE)
**Goal**: Verify rename works end-to-end
1. Open: http://localhost:5000 (or HF Spaces URL)
2. Upload test file: `rename_test.txt`
3. Right-click file β "Rename" β `renamed_file.txt`
4. Verify: File appears with new name
5. Download to verify content intact
6. Check logs: Should see `[RENAME] SUCCESS`
**Pass Criteria**:
- β File renamed successfully
- β UI updates immediately
- β Log shows [RENAME] SUCCESS
#### Test B: Folder Operations
**Goal**: Verify folders work with new rename
1. Create folder: `TestFolder`
2. Upload 5 files into it
3. Rename folder: `TestFolder` β `RenamedFolder`
4. Verify: All 5 files still accessible in new folder
5. Check logs: Should see [RENAME] SUCCESS with all files preserved
**Pass Criteria**:
- β Folder renamed with contents
- β Files accessible after rename
- β No data loss
#### Test C: Delete Operations
1. Upload file: `delete_test.txt`
2. Delete it
3. Verify: File removed from list
4. Check logs: Should see `[DELETE_FILE] SUCCESS`
**Pass Criteria**:
- β File removed
- β Delete confirmation modal shown
- β Log shows [DELETE_FILE] SUCCESS
#### Test D: Cache Behavior
**Goal**: Verify 60-second cache works
1. Upload file: `cache_test.txt`
2. Open DevTools (F12) β Network tab
3. Reload page within 30 seconds
4. Observe: List call should be instant (using cache)
5. Wait 65 seconds
6. Reload page
7. Observe: Slightly slower (fresh from server)
**Pass Criteria**:
- β First reload is instant (<100ms)
- β After 60s, fresh data fetched
- β No errors in console
---
### PHASE 3: Automated Stress Testing (60 minutes)
#### Step 1: Start Server
```bash
# Terminal 1: Start Flask backend
cd c:\Users\mohat\OneDrive\Desktop\Doc
python -m server.app
# Should see: Running on http://127.0.0.1:5000
```
#### Step 2: Run Stress Tests
```bash
# Terminal 2: Run stress test suite (LOCAL mode)
cd c:\Users\mohat\OneDrive\Desktop\Doc
python stress_test.py http://localhost:5000
```
**Expected Output**:
```
============================================================
DOCVAULT STRESS TEST SUITE
============================================================
Base URL: http://localhost:5000
User: stress_test_user
Timeout: 30s
Checking server connectivity...
β Server is healthy
π₯ TEST 1: BULK UPLOAD (50 files)
----------------------------------------
β bulk_upload_all_succeed
β bulk_upload_speed
Uploaded: 50/50
Total time: 25.34s
Avg per file: 0.51s
π₯ TEST 2: FOLDER RENAME STRESS (30 files in folder)
----------------------------------------
β folder_rename
β folder_rename_speed
β folder_rename_data_preserved
Renaming folder...
Time: 2.15s
π₯ TEST 3: RAPID OPERATIONS (Race Conditions)
----------------------------------------
β rapid_ops_20_cycles
β rapid_seq_operations
π§ͺ TEST 4: CACHE VALIDATION (60s TTL)
----------------------------------------
β cache_first_list
β cache_second_list
π§ͺ TEST 5: ERROR HANDLING
----------------------------------------
β error_handling_delete_nonexistent
β error_handling_rename_nonexistent
β error_handling_list_nonexistent
============================================================
STRESS TEST RESULTS
============================================================
β Passed: 16
β Failed: 0
Total: 16
PERFORMANCE METRICS:
bulk_upload: avg=0.51s, max=1.23s, count=50
folder_rename: avg=2.15s, max=2.15s, count=1
list_fresh: avg=0.05s, max=0.05s, count=1
list_cached: avg=0.02s, max=0.02s, count=1
============================================================
```
#### Step 3: Check Logs
```bash
# Review logs for any warnings or errors
tail -f logs/docvault.log | grep -E "\[UPLOAD\]|\[DELETE\]|\[RENAME\]|\[ERROR\]"
```
**Look For**:
- β All operations have START and SUCCESS
- β No EXCEPTION entries
- β οΈ Any FAIL entries (investigate)
#### Step 4: Interpret Results
**Perfect Scenario**:
- All 16 tests pass
- No race conditions detected
- Performance metrics reasonable
- No errors in logs
**Warning Scenarios**:
- Bulk upload > 30 seconds: May be slow
- Folder rename > 5 seconds: Performance issue
- Failed rapid operations: Race condition risk
- Exceptions in logs: Critical issue
**Failure Scenario**:
- Tests fail: Do NOT deploy
- Race conditions detected: Do NOT deploy
- Exceptions: Do NOT deploy
---
## π TEST RESULTS TEMPLATE
Record results here:
```
TEST EXECUTION REPORT
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Date: ________________
Environment: [ ] LOCAL [ ] HF_SPACES
Tester: ________________
MANUAL TESTS:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Test A - Rename Feature: [ ] PASS [ ] FAIL
Test B - Folder Operations: [ ] PASS [ ] FAIL
Test C - Delete Operations: [ ] PASS [ ] FAIL
Test D - Cache Behavior: [ ] PASS [ ] FAIL
AUTOMATED STRESS TESTS:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Total Tests: ____
Passed: ____
Failed: ____
Race Conditions: [ ] YES [ ] NO
PERFORMANCE METRICS (from stress test):
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Avg Upload Time: ______ seconds
Max Rename Time: ______ seconds
Cache Hit Time: ______ seconds
List Operation Time: ______ seconds
ISSUES FOUND:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
[ ] None
[ ] Minor (document & monitor)
[ ] Major (fix before deploy)
[ ] Critical (DO NOT DEPLOY)
Issues:
1. ________________________________________
2. ________________________________________
3. ________________________________________
LOGS STATUS:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
[ ] All operations logged correctly
[ ] No exceptions in logs
[ ] Errors are meaningful
[ ] Performance data captured
FINAL VERDICT:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
[ ] READY FOR PRODUCTION
[ ] NEEDS MORE TESTING
[ ] DO NOT DEPLOY
Comments:
__________________________________________________________________
__________________________________________________________________
Signed: _________________________ Date: ________________
```
---
## π₯ CRITICAL ISSUES TO WATCH FOR
### Red Flag #1: Upload Failures
```
[UPLOAD_FILE] FAIL | reason=permission_denied
```
β Check HF token permissions
### Red Flag #2: Rename Failures
```
[RENAME] FAIL | error=atomic_commit_failed
```
β Check HF API availability
### Red Flag #3: Race Conditions
```
rapid_ops test: 3/20 operations failed
```
β Investigate cache invalidation timing
### Red Flag #4: Slow Performance
```
bulk_upload total time: 180s (should be <60s)
```
β Check network/HF API performance
### Red Flag #5: Memory Leaks
```
Processing time increases over 150+ operations
```
β Check for unclosed file handles
---
## π― SUCCESS CRITERIA FOR PRODUCTION DEPLOYMENT
**All Must Be True**:
- β
Manual tests: 4/4 passing
- β
Stress tests: 16/16 passing
- β
No race conditions detected
- β
No exceptions in logs
- β
Performance acceptable (bulk upload <60s)
- β
Cache working (list cached <100ms)
- β
All logs readable and structured
- β
Zero data loss observed
**If Any Fails**:
β DO NOT DEPLOY
β Investigate & fix
β Re-test
---
## π DEPLOYMENT STEPS (After Passing Tests)
1. **Backup Current HF Repo**
```bash
# Create a snapshot of current state
# Document in deployment log
```
2. **Deploy Code**
- Push fixes to HF Space git repo
- Or: Upload files directly to Space
3. **Restart Application**
- HF Spaces: App auto-restarts on code change
- Local: Restart Flask server
4. **Smoke Test**
- Upload test file
- Rename it
- Delete it
- Check logs are generated
5. **Monitor for 24 Hours**
- Check logs regularly
- Monitor error rates
- Gather user feedback
---
## π LOGGING REFERENCE
### Log Format
```
[OPERATION] STATUS | user=X | details=Y | duration=Z
```
### Example Logs
```
[UPLOAD_FILE] START | user=default_user | file=report.pdf | size=2097152
[UPLOAD_FILE] SUCCESS | user=default_user | file=report.pdf
[DELETE_FILE] START | user=default_user | path=report.pdf
[DELETE_FILE] SUCCESS | user=default_user | path=report.pdf
[RENAME] START | user=default_user | path=old_name | new_name=new_name
[RENAME] SUCCESS | user=default_user | old_path=old_name | new_name=new_name
[LIST] START | user=default_user | path=root
[LIST] SUCCESS | user=default_user | path=root | files=42 | folders=5
```
### What Each Field Means
- `[OPERATION]` - What's happening (UPLOAD, DELETE, RENAME, etc.)
- `STATUS` - Result (START, SUCCESS, FAIL, EXCEPTION)
- `user=X` - Which user (always check: should be isolated)
- `details` - Operation context (files, paths, sizes)
- `duration` - How long it took (helps spot performance issues)
---
## π TROUBLESHOOTING
### Stress Test Won't Run
```bash
# Error: No module named 'requests'
pip install requests
# Error: Connection refused
# Make sure Flask app is running: python -m server.app
```
### Tests Fail With Timeouts
- Check: Server is responding normally
- Check: Network connectivity
- Increase: TIMEOUT variable in stress_test.py
### Logs Not Appearing
- Check: Logs directory exists
- Check: config.py LOG_LEVEL = "INFO"
- Check: Flask app has logging enabled
---
**NEXT STEP**: Execute this entire procedure and record results in the template above.
**THEN**: If all passes β **YOU'RE PRODUCTION READY** β
---
*Ready to test? Let's ensure this app is truly production-grade.*
|