Skip to content

Commit

Permalink
chore: test data freshness #19
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed Jul 11, 2024
1 parent 24a1b0b commit 4eee121
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 14 deletions.
2 changes: 2 additions & 0 deletions screenpipe-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ crossbeam = "0.8"
[dev-dependencies]
tempfile = "3.3.0"

reqwest = { version = "0.11", features = ["json"] }

[features]
static-ffmpeg = ["ffmpeg-next/static"]

Expand Down
18 changes: 9 additions & 9 deletions screenpipe-server/src/bin/screenpipe-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use std::{
};

use clap::Parser;
use log::{info, LevelFilter, warn};
use colored::Colorize;
use log::{info, warn, LevelFilter};
use screenpipe_audio::{
default_input_device, default_output_device, list_audio_devices, parse_device_spec,
};
use colored::Colorize;

use screenpipe_server::{start_continuous_recording, DatabaseManager, ResourceMonitor, Server}; // Import the list_audio_devices function
#[derive(Parser)]
Expand Down Expand Up @@ -47,6 +47,10 @@ struct Cli {
/// List available audio devices
#[arg(long)]
list_audio_devices: bool,

/// Data directory
#[arg(long, default_value_t = String::from("./data"))]
data_dir: String,
}

#[tokio::main]
Expand Down Expand Up @@ -119,7 +123,9 @@ async fn main() -> anyhow::Result<()> {
ResourceMonitor::new(cli.memory_threshold, cli.runtime_threshold)
.start_monitoring(Duration::from_secs(10)); // Log every 10 seconds

let local_data_dir = Arc::new(ensure_local_data_dir()?);
let local_data_dir = cli.data_dir; // TODO: Use $HOME/.screenpipe/data
fs::create_dir_all(&local_data_dir)?;
let local_data_dir = Arc::new(local_data_dir);
let local_data_dir_record = local_data_dir.clone();
let db = Arc::new(
DatabaseManager::new(&format!("{}/db.sqlite", local_data_dir))
Expand Down Expand Up @@ -163,9 +169,3 @@ async fn main() -> anyhow::Result<()> {
tokio::time::sleep(Duration::from_secs(1)).await;
}
}

fn ensure_local_data_dir() -> anyhow::Result<String> {
let local_data_dir = "./data".to_string(); // TODO: Use $HOME/.screenpipe/data
fs::create_dir_all(&local_data_dir)?;
Ok(local_data_dir)
}
63 changes: 58 additions & 5 deletions screenpipe-server/tests/audio_vision_integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,61 @@
use std::{sync::mpsc, thread, time::Duration};
use reqwest;
use serde_json::Value;
use std::time::{Duration, Instant};

use screenpipe_server::VideoCapture;
#[tokio::test]
async fn test_screen_capture_to_api_delay() {
// rm the data directory
std::fs::remove_dir_all("../data-test").unwrap_or_default();

#[test]
fn test_audio_video_capture() {
assert!(true) // TODO
println!("Run: ./target/release/screenpipe --data-dir ./data-test");

let wikipedia_url = "https://en.wikipedia.org/wiki/Rust_(programming_language)";
println!("Go to this Wikipedia page: {}", wikipedia_url);

// wait 2 seconds
tokio::time::sleep(Duration::from_secs(5)).await;

// Record start time
let start_time = Instant::now();

// Initialize client
let client = reqwest::Client::new();

// Poll the API until the desired phrase is found
let mut found = false;
while !found {
let response: Value = client
.get("http://localhost:3030/search?q=Graydon&limit=5&offset=0")
.send()
.await
.expect("Failed to send request")
.json()
.await
.expect("Failed to parse JSON");

let data: Vec<Value> = response["data"].as_array().unwrap().to_vec();

found = data
.iter()
.filter(|item| item["type"] == "OCR")
.any(|item| {
item["content"]["text"]
.as_str()
.unwrap()
.contains("without a garbage collector")
});

if !found {
tokio::time::sleep(Duration::from_secs(1)).await;
}
}

println!("Found the phrase!");
println!("Time elapsed: {:?}", start_time.elapsed());

// Mac M3 max: Time elapsed: 33.516971916s
// Mac M3 max: Time elapsed: 153.62804525s

// You can add assertions here if needed
// assert!(elapsed_time < Duration::from_secs(30), "Test took too long");
}

0 comments on commit 4eee121

Please sign in to comment.