mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-05-19 05:45:01 -04:00
Refactor CI workflow and update test configurations
- Removed the setup step for native dependencies in the CI workflow to streamline the build process. - Updated the `copy_action_test` to include conflict resolution options for better handling of file conflicts. - Enhanced metadata handling in `entry_move_integrity_test` to include job policies. - Added metadata to event handling in `file_structure_test` for improved context during file operations. - Updated service configuration in `file_sync_simple_test` and `file_sync_test` to use `fs_watcher_enabled` and included default logging settings. - Deleted the outdated README.md from the tests directory to reduce clutter and improve documentation focus.
This commit is contained in:
3
.github/workflows/core_tests.yml
vendored
3
.github/workflows/core_tests.yml
vendored
@@ -40,9 +40,6 @@ jobs:
|
||||
path: target
|
||||
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
- name: Setup native dependencies
|
||||
run: cargo run -p xtask -- setup
|
||||
|
||||
- name: Build core
|
||||
run: cargo build -p sd-core --verbose
|
||||
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
# Sync Integration Tests
|
||||
|
||||
This directory contains integration tests for Spacedrive's sync system.
|
||||
|
||||
## Quick Links
|
||||
|
||||
- **[SYNC_TESTS.md](./SYNC_TESTS.md)** - Complete documentation of all sync test files
|
||||
- **[SYNC_HARNESS_USAGE.md](./SYNC_HARNESS_USAGE.md)** - How to use shared test utilities
|
||||
- **[REFACTORING_SUMMARY.md](./REFACTORING_SUMMARY.md)** - Refactoring impact summary
|
||||
- **[helpers/README.md](./helpers/README.md)** - Helper module documentation
|
||||
|
||||
## Writing New Tests
|
||||
|
||||
Use the shared test harness for two-device sync tests:
|
||||
|
||||
```rust
|
||||
use helpers::TwoDeviceHarnessBuilder;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_my_scenario() -> anyhow::Result<()> {
|
||||
let harness = TwoDeviceHarnessBuilder::new("my_scenario")
|
||||
.await?
|
||||
.build()
|
||||
.await?;
|
||||
|
||||
// Alice indexes a location
|
||||
harness.add_and_index_location_alice("/path", "Name").await?;
|
||||
|
||||
// Wait for sync to complete
|
||||
harness.wait_for_sync(Duration::from_secs(60)).await?;
|
||||
|
||||
// Capture snapshot
|
||||
harness.capture_snapshot("final").await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
## Running Tests
|
||||
|
||||
```bash
|
||||
# Run all sync tests
|
||||
cargo test -p sd-core --test 'sync_*' -- --test-threads=1 --nocapture
|
||||
|
||||
# Run specific test file
|
||||
cargo test -p sd-core --test sync_realtime_test -- --test-threads=1 --nocapture
|
||||
|
||||
# Run specific test
|
||||
cargo test -p sd-core --test sync_realtime_test test_realtime_sync_alice_to_bob -- --nocapture
|
||||
```
|
||||
|
||||
**Important:** Use `--test-threads=1` to prevent tests from interfering with each other.
|
||||
|
||||
## Test Snapshots
|
||||
|
||||
All tests capture comprehensive snapshots to:
|
||||
```
|
||||
~/Library/Application Support/spacedrive/sync_tests/snapshots/{test_name}_{timestamp}/
|
||||
```
|
||||
|
||||
Each snapshot includes:
|
||||
- `test.log` - Complete trace output
|
||||
- `alice/database.db` - Alice's database
|
||||
- `alice/sync.db` - Alice's sync database
|
||||
- `alice/logs/` - Alice's library logs
|
||||
- `bob/database.db` - Bob's database
|
||||
- `bob/sync.db` - Bob's sync database
|
||||
- `bob/logs/` - Bob's library logs
|
||||
- `summary.md` - Test results summary
|
||||
|
||||
## Current Test Files
|
||||
|
||||
### Core Sync Tests
|
||||
- `sync_realtime_test.rs` - Real-time sync between pre-paired devices
|
||||
- `sync_backfill_test.rs` - Initial backfill when devices first connect
|
||||
- `sync_backfill_race_test.rs` - Race condition between backfill and live events
|
||||
- `sync_metrics_test.rs` - Metrics tracking validation
|
||||
- `sync_event_log_test.rs` - Event logging system tests
|
||||
- `sync_setup_test.rs` - Sync setup with subprocess framework
|
||||
|
||||
### Helper Infrastructure
|
||||
- `helpers/sync_harness.rs` - Shared test utilities
|
||||
- `helpers/sync_transport.rs` - Mock network transport
|
||||
- `helpers/test_volumes.rs` - Volume testing utilities
|
||||
- `helpers/mod.rs` - Module exports
|
||||
|
||||
## Refactoring Stats
|
||||
|
||||
**55% code reduction** across refactored tests:
|
||||
- Eliminated **2046 lines** of duplicated code
|
||||
- Added **600 lines** of shared infrastructure
|
||||
- Net savings: **~1446 lines**
|
||||
|
||||
See [REFACTORING_SUMMARY.md](./REFACTORING_SUMMARY.md) for details.
|
||||
@@ -55,6 +55,7 @@ async fn test_copy_action_construction() {
|
||||
]),
|
||||
destination: SdPath::local(dest_dir.clone()),
|
||||
options: CopyOptions {
|
||||
conflict_resolution: ConflictResolution::Overwrite,
|
||||
overwrite: false,
|
||||
copy_method: CopyMethod::Auto,
|
||||
verify_checksum: true,
|
||||
|
||||
@@ -107,6 +107,7 @@ async fn test_entry_metadata_preservation_on_move() {
|
||||
path: SdPath::local(source_dir.clone()),
|
||||
name: Some("Source".to_string()),
|
||||
mode: IndexMode::Deep,
|
||||
job_policies: None,
|
||||
})
|
||||
.unwrap(),
|
||||
)
|
||||
@@ -416,6 +417,7 @@ async fn test_child_entry_metadata_preservation_on_parent_move() {
|
||||
path: SdPath::local(source_dir.clone()),
|
||||
name: Some("Source".to_string()),
|
||||
mode: IndexMode::Deep,
|
||||
job_policies: None,
|
||||
};
|
||||
let add_loc_action = LocationAddAction::from_input(add_loc_input).unwrap();
|
||||
let _add_output = action_manager
|
||||
|
||||
@@ -98,6 +98,7 @@ async fn map_file_structure_per_phase() -> Result<(), Box<dyn std::error::Error>
|
||||
if let Event::ResourceChangedBatch {
|
||||
resource_type,
|
||||
resources,
|
||||
metadata,
|
||||
} = event
|
||||
{
|
||||
if resource_type == "file" {
|
||||
|
||||
@@ -34,8 +34,9 @@ impl FileSyncTestSetup {
|
||||
services: sd_core::config::ServiceConfig {
|
||||
networking_enabled: false,
|
||||
volume_monitoring_enabled: false,
|
||||
location_watcher_enabled: false,
|
||||
fs_watcher_enabled: false,
|
||||
},
|
||||
logging: sd_core::config::LoggingConfig::default(),
|
||||
};
|
||||
config.save()?;
|
||||
|
||||
|
||||
@@ -60,8 +60,9 @@ impl FileSyncTestSetup {
|
||||
services: sd_core::config::ServiceConfig {
|
||||
networking_enabled: false,
|
||||
volume_monitoring_enabled: false,
|
||||
location_watcher_enabled: false,
|
||||
fs_watcher_enabled: false,
|
||||
},
|
||||
logging: sd_core::config::LoggingConfig::default(),
|
||||
};
|
||||
config.save()?;
|
||||
|
||||
|
||||
@@ -2,12 +2,6 @@
|
||||
|
||||
Shared utilities for integration tests to reduce duplication and improve maintainability.
|
||||
|
||||
## Quick Links
|
||||
|
||||
- **[Sync Harness Usage Guide](../SYNC_HARNESS_USAGE.md)** - How to use the shared sync test utilities
|
||||
- **[Refactoring Example](../REFACTORING_EXAMPLE.md)** - Before/after comparison showing benefits
|
||||
- **[Sync Tests Documentation](../SYNC_TESTS.md)** - Complete sync test suite documentation
|
||||
|
||||
## Modules
|
||||
|
||||
### `sync_harness.rs` - Two-Device Sync Test Utilities
|
||||
@@ -17,6 +11,7 @@ Provides a comprehensive test harness for sync integration tests that eliminates
|
||||
**Key Components:**
|
||||
|
||||
#### `TwoDeviceHarnessBuilder`
|
||||
|
||||
Builder for creating pre-configured two-device test environments.
|
||||
|
||||
```rust
|
||||
@@ -30,6 +25,7 @@ let harness = TwoDeviceHarnessBuilder::new("my_test")
|
||||
```
|
||||
|
||||
Automatically handles:
|
||||
|
||||
- Creating test directories
|
||||
- Initializing tracing to files
|
||||
- Setting up cores and libraries
|
||||
@@ -39,6 +35,7 @@ Automatically handles:
|
||||
- Setting sync state
|
||||
|
||||
#### `TwoDeviceHarness`
|
||||
|
||||
The resulting test harness with convenient methods:
|
||||
|
||||
```rust
|
||||
@@ -61,21 +58,26 @@ harness.transport_alice;
|
||||
#### Helper Functions
|
||||
|
||||
**Configuration:**
|
||||
|
||||
- `TestConfigBuilder` - Build test configs with custom filters
|
||||
- `init_test_tracing()` - Standard tracing setup
|
||||
|
||||
**Device Setup:**
|
||||
|
||||
- `register_device()` - Register a device in a library
|
||||
- `set_all_devices_synced()` - Mark devices as synced (prevent auto-backfill)
|
||||
|
||||
**Waiting:**
|
||||
|
||||
- `wait_for_indexing()` - Wait for indexing job completion
|
||||
- `wait_for_sync()` - Sophisticated sync completion detection
|
||||
|
||||
**Operations:**
|
||||
|
||||
- `add_and_index_location()` - Create and index a location
|
||||
|
||||
**Snapshots:**
|
||||
|
||||
- `create_snapshot_dir()` - Create timestamped snapshot directory
|
||||
- `SnapshotCapture` - Utilities for capturing databases, logs, events
|
||||
|
||||
@@ -84,6 +86,7 @@ harness.transport_alice;
|
||||
Mock implementation of `NetworkTransport` for testing sync without real networking.
|
||||
|
||||
**Key Features:**
|
||||
|
||||
- Immediate message delivery (like production)
|
||||
- Request/response handling for backfill
|
||||
- Device blocking/unblocking (simulate offline)
|
||||
@@ -91,6 +94,7 @@ Mock implementation of `NetworkTransport` for testing sync without real networki
|
||||
- Queue inspection
|
||||
|
||||
**Usage:**
|
||||
|
||||
```rust
|
||||
// Single device
|
||||
let transport = MockTransport::new_single(device_id);
|
||||
@@ -114,11 +118,13 @@ Helper functions for creating mock volumes in tests (used by `sync_backfill_test
|
||||
## Benefits of Using Shared Utilities
|
||||
|
||||
### Code Reduction
|
||||
|
||||
- **~200 lines** of boilerplate eliminated per test
|
||||
- **~2887 lines** saved across 6 sync tests (65% reduction)
|
||||
- **One source of truth** for test patterns
|
||||
|
||||
### Consistency
|
||||
|
||||
- Same tracing setup everywhere
|
||||
- Same config creation
|
||||
- Same device registration
|
||||
@@ -126,12 +132,14 @@ Helper functions for creating mock volumes in tests (used by `sync_backfill_test
|
||||
- Same waiting algorithms
|
||||
|
||||
### Maintainability
|
||||
|
||||
- Fix bugs in one place
|
||||
- Add features once, benefit everywhere
|
||||
- Clear upgrade path for tests
|
||||
- Easier code reviews
|
||||
|
||||
### Reliability
|
||||
|
||||
- Battle-tested algorithms
|
||||
- Sophisticated sync detection
|
||||
- Comprehensive snapshot capture
|
||||
@@ -193,6 +201,7 @@ When adding new shared utilities:
|
||||
5. **Export from `mod.rs`**
|
||||
|
||||
Keep utilities:
|
||||
|
||||
- **Generic** - Useful for multiple tests
|
||||
- **Well-documented** - Clear purpose and usage
|
||||
- **Battle-tested** - Used by actual tests
|
||||
|
||||
Reference in New Issue
Block a user