Skip to content

Commit

Permalink
Reduce delay
Browse files Browse the repository at this point in the history
  • Loading branch information
cygaar committed Dec 17, 2024
1 parent c783942 commit fb624f5
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions rig-mongodb/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,6 @@ const DATABASE_NAME: &str = "rig";
const USERNAME: &str = "riguser";
const PASSWORD: &str = "rigpassword";

async fn create_search_index(collection: &Collection<bson::Document>) {
let mut attempts = 0;
let max_attempts = 5;

while attempts < max_attempts {
match collection
.create_search_index(
SearchIndexModel::builder()
.name(Some(VECTOR_SEARCH_INDEX_NAME.to_string()))
.index_type(Some(mongodb::SearchIndexType::VectorSearch))
.definition(doc! {
"fields": [{
"numDimensions": 1536,
"path": "embedding",
"similarity": "cosine",
"type": "vector"
}]
})
.build(),
)
.await
{
Ok(_) => return,
Err(_) => {
println!("Waiting for MongoDB to be ready... Attempts remaining: {}", max_attempts - attempts - 1);
sleep(Duration::from_secs(5)).await;
attempts += 1;
}
}
}
panic!("Failed to create search index after {} attempts", max_attempts);
}

#[tokio::test]
async fn vector_search_test() {
// Initialize OpenAI client
Expand Down Expand Up @@ -104,7 +71,7 @@ async fn vector_search_test() {
.await
.unwrap();

sleep(Duration::from_secs(15)).await;
sleep(Duration::from_secs(5)).await;

// Query the index
let results = index
Expand All @@ -124,6 +91,39 @@ async fn vector_search_test() {
)
}

async fn create_search_index(collection: &Collection<bson::Document>) {

Check warning on line 94 in rig-mongodb/tests/integration_tests.rs

View workflow job for this annotation

GitHub Actions / stable / fmt

Diff in /home/runner/work/rig/rig/rig-mongodb/tests/integration_tests.rs
let mut attempts = 0;
let max_attempts = 5;

while attempts < max_attempts {
match collection
.create_search_index(
SearchIndexModel::builder()
.name(Some(VECTOR_SEARCH_INDEX_NAME.to_string()))
.index_type(Some(mongodb::SearchIndexType::VectorSearch))
.definition(doc! {
"fields": [{
"numDimensions": 1536,
"path": "embedding",
"similarity": "cosine",
"type": "vector"
}]
})
.build(),
)
.await
{

Check warning on line 115 in rig-mongodb/tests/integration_tests.rs

View workflow job for this annotation

GitHub Actions / stable / fmt

Diff in /home/runner/work/rig/rig/rig-mongodb/tests/integration_tests.rs
Ok(_) => return,
Err(_) => {
println!("Waiting for MongoDB to be ready... Attempts remaining: {}", max_attempts - attempts - 1);
sleep(Duration::from_secs(5)).await;
attempts += 1;
}
}

Check warning on line 122 in rig-mongodb/tests/integration_tests.rs

View workflow job for this annotation

GitHub Actions / stable / fmt

Diff in /home/runner/work/rig/rig/rig-mongodb/tests/integration_tests.rs
}
panic!("Failed to create search index after {} attempts", max_attempts);
}

async fn bootstrap_collection(host: String, port: u16) -> Collection<bson::Document> {
// Initialize MongoDB client
let options = ClientOptions::parse(format!(
Expand Down

0 comments on commit fb624f5

Please sign in to comment.