|
| 1 | +// Copyright 2025 The Drasi Authors. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +//! Integration tests for the redb-backed WAL provider. |
| 16 | +//! |
| 17 | +//! The WAL provider is the primary feature added in this PR and is wired into |
| 18 | +//! every instance, so these tests verify: |
| 19 | +//! - `RedbWalProvider` can be created from a directory path without panicking |
| 20 | +//! - `DrasiLib::builder().with_wal_provider(...)` accepts the provider and the |
| 21 | +//! instance reaches Running and stops cleanly |
| 22 | +//! |
| 23 | +//! Per-source WAL file/directory creation is exercised by the `drasi-wal-redb` |
| 24 | +//! crate's own tests, since it only happens once a source appends events. |
| 25 | +
|
| 26 | +use anyhow::Result; |
| 27 | +use drasi_lib::DrasiLib; |
| 28 | +use drasi_wal_redb::RedbWalProvider; |
| 29 | +use std::sync::Arc; |
| 30 | +use tempfile::TempDir; |
| 31 | + |
| 32 | +/// Test that RedbWalProvider can be created with a valid directory path. |
| 33 | +#[test] |
| 34 | +fn test_redb_wal_provider_creation() { |
| 35 | + let temp_dir = TempDir::new().expect("Failed to create temp directory"); |
| 36 | + let wal_path = temp_dir.path().join("wal"); |
| 37 | + |
| 38 | + let provider = RedbWalProvider::new(&wal_path); |
| 39 | + |
| 40 | + // Provider should be created successfully. |
| 41 | + drop(provider); |
| 42 | +} |
| 43 | + |
| 44 | +/// Test that DrasiLib builder accepts a redb WAL provider and the instance |
| 45 | +/// starts and stops cleanly. |
| 46 | +#[tokio::test] |
| 47 | +async fn test_drasi_lib_builder_with_redb_wal_provider() -> Result<()> { |
| 48 | + let temp_dir = TempDir::new()?; |
| 49 | + let wal_path = temp_dir.path().join("wal"); |
| 50 | + |
| 51 | + let provider = RedbWalProvider::new(&wal_path); |
| 52 | + |
| 53 | + let core = DrasiLib::builder() |
| 54 | + .with_id("test-wal-provider") |
| 55 | + .with_wal_provider(Arc::new(provider)) |
| 56 | + .build() |
| 57 | + .await?; |
| 58 | + |
| 59 | + core.start().await?; |
| 60 | + assert!(core.is_running().await); |
| 61 | + drasi_lib::wait_for_status( |
| 62 | + &core.component_graph(), |
| 63 | + "__component_graph__", |
| 64 | + &[drasi_lib::channels::ComponentStatus::Running], |
| 65 | + std::time::Duration::from_secs(5), |
| 66 | + ) |
| 67 | + .await |
| 68 | + .expect("component graph should reach Running"); |
| 69 | + |
| 70 | + core.stop().await?; |
| 71 | + assert!(!core.is_running().await); |
| 72 | + |
| 73 | + Ok(()) |
| 74 | +} |
0 commit comments