tsdb_timon 1.1.3

Efficient local storage and Amazon S3-compatible data synchronization for time-series data, leveraging Parquet for storage and DataFusion for querying, all wrapped in a simple and intuitive API.
Documentation
# Code Coverage Guide

This project uses `cargo-tarpaulin` for code coverage analysis.

## Installation

If you don't have `cargo-tarpaulin` installed:

```bash
cargo install cargo-tarpaulin
```

## Recommended Usage: Use `coverage.sh`

**We recommend using the `coverage.sh` script instead of calling `cargo tarpaulin` directly:**

```bash
bash coverage.sh
```

Or if you have execute permissions:

```bash
./scripts/coverage.sh
```

### Why use `coverage.sh`?

The `coverage.sh` script is configured with project-specific settings:

1. **Excludes platform-specific code**: Automatically excludes `src/lib.rs` (Android/iOS platform code) and `src/main.rs` from coverage, as these contain platform-specific implementations that shouldn't be included in coverage metrics.

2. **Prevents race conditions**: Uses `--test-threads=1` to avoid race conditions in file system-based tests, ensuring consistent and reliable test results.

3. **Consistent output**: Outputs to stdout in a standardized format, making it easy to parse and integrate with CI/CD pipelines.

4. **Accepts additional arguments**: You can still pass additional arguments to customize the run:
   ```bash
   bash coverage.sh --out Html --output-dir ./coverage-report
   ```

## Basic Usage (Alternative)

If you need to run `cargo tarpaulin` directly, you can use:

### Run coverage for all tests

```bash
cargo tarpaulin --out Html --output-dir ./coverage-report
```

This will:
- Run all tests
- Generate an HTML coverage report in `./coverage-report/`
- Open `coverage-report/tarpaulin-report.html` in your browser to view the report

### Run coverage with terminal output

```bash
cargo tarpaulin --out Stdout
```

**Note**: When running directly, remember to exclude `src/lib.rs` and `src/main.rs`, and use `--test-threads=1` for consistency:
```bash
cargo tarpaulin --out Stdout --exclude-files "src/lib.rs" --exclude-files "src/main.rs" -- --test-threads=1
```

### Generate multiple output formats

```bash
cargo tarpaulin --out Html --out Xml --out Stdout --output-dir ./coverage-report
```

### Exclude files from coverage

```bash
cargo tarpaulin --exclude-files 'src/tests/*' --out Html --output-dir ./coverage-report
```

### Set coverage threshold

```bash
cargo tarpaulin --out Html --output-dir ./coverage-report --fail-under 80
```

This will fail if coverage is below 80%.

## Advanced Options

### Include integration tests

```bash
cargo tarpaulin --tests --out Html --output-dir ./coverage-report
```

### Include examples

```bash
cargo tarpaulin --examples --out Html --output-dir ./coverage-report
```

### Include benchmarks

```bash
cargo tarpaulin --benches --out Html --output-dir ./coverage-report
```

### Timeout for tests

```bash
cargo tarpaulin --timeout 300 --out Html --output-dir ./coverage-report
```

### Skip tests that take too long

```bash
cargo tarpaulin --skip-clean --out Html --output-dir ./coverage-report
```

## Alternative: cargo-llvm-cov

For more detailed coverage information, you can use `cargo-llvm-cov`:

```bash
# Install
cargo install cargo-llvm-cov

# Run coverage
cargo llvm-cov --html --output-dir ./coverage-report

# Generate report
cargo llvm-cov --lcov --output-path ./coverage/lcov.info
```

## CI/CD Integration

### GitHub Actions Example

```yaml
- name: Generate coverage report
  run: |
    cargo install cargo-tarpaulin
    cargo tarpaulin --out Xml --output-dir ./coverage-report
    cargo tarpaulin --out Html --output-dir ./coverage-report

- name: Upload coverage to Codecov
  uses: codecov/codecov-action@v3
  with:
    files: ./coverage-report/cobertura.xml
```

## Viewing Reports

After generating HTML reports, open them in your browser:

```bash
# Linux
xdg-open coverage-report/tarpaulin-report.html

# macOS
open coverage-report/tarpaulin-report.html

# Windows
start coverage-report/tarpaulin-report.html
```

## Common Issues

1. **Tests timeout**: Increase timeout with `--timeout` flag (e.g., `bash coverage.sh --timeout 300`)
2. **Missing coverage for some files**: Check if they're excluded (lib.rs and main.rs are excluded by default in `coverage.sh`) or not compiled
3. **Slow coverage runs**: Use `--skip-clean` to avoid rebuilding (e.g., `bash coverage.sh --skip-clean`)
4. **Race conditions in tests**: The `coverage.sh` script already uses `--test-threads=1` to prevent this. If running directly, make sure to include this flag.

---

## Current Coverage Status

**Coverage: 85.16%** (1,698 / 1,994 lines covered)  
**Tests: 485 comprehensive unit tests**  
**Status: ✅ Production Ready**

### Coverage by Module

| Module | Coverage | Status |
|--------|----------|--------|
| sql_query_parser.rs | 94.44% | ✅ Excellent |
| cloud_sync.rs | 93.25% | ⚠️ Requires S3 |
| errors.rs | 98.68% | ✅ Excellent |
| db_manager.rs | 82.75% | ✅ Good |
| helpers.rs | 81.62% | ✅ Good |
| mod.rs | 73.22% | ⚠️ API wrappers |
| security.rs | 66.67% | ⚠️ Platform-specific |

### What's Covered ✅

- All critical business logic (CRUD operations, queries, data validation)
- Normal operation paths with comprehensive test coverage
- Common error conditions and edge cases
- File system operations and metadata management
- Concurrent access patterns and locking mechanisms
- SQL parsing for standard queries

### Why Some Lines Are Uncovered ⚠️

The remaining **~15%** uncovered lines are justified and acceptable:

1. **Mutex Poisoning** (~30 lines) - Requires thread panics while holding locks
2. **System Call Failures** (~20 lines) - Time before UNIX epoch, regex compilation failures
3. **S3/Cloud Operations** (~17 lines) - Requires integration infrastructure
4. **Corrupted Data Handling** (~100 lines) - Requires malformed Parquet files and schema mismatches
5. **Platform-Specific Code** (~2 lines) - Debugger detection (Linux ptrace)
6. **Type Safety Guards** (~90 lines) - Defensive code for data format edge cases
7. **API Wrapper Success Paths** (~60 lines) - Thin wrappers over tested core functionality

These lines represent defensive programming for exceptional conditions that are impractical to test in unit tests.

### Recommendations

**Current 85.16% coverage is excellent for production use** because:
- All critical business logic is thoroughly tested
- 485 tests provide strong regression protection
- Common error paths are validated
- Edge cases that matter are covered

**To reach 90%+ would require:**
- Integration test environment with MinIO/S3
- Chaos testing framework to inject failures
- Mock infrastructure for system calls
- Platform-specific test runners

**Estimated effort:** 3-4 weeks for marginal benefit  
**Recommendation:** Not worth the investment. Focus on integration tests for cloud operations when infrastructure is available.

---

## Coverage History

| Date | Coverage | Lines | Tests | Notes |
|------|----------|-------|-------|-------|
| Jan 26, 2026 | **85.16%** | 1,698/1,994 | **485** | Current comprehensive coverage |
| Jan 25, 2026 | 84.05% | 1,676/1,994 | 494 | After helpers.rs improvements |
| Jan 24, 2026 | 82.90% | - | 423 | Before db_manager improvements |