Repository: meilisearch/meilisearch
File: crates/meilisearch/tests/tasks/mod.rs (Rust)

Code before:
}

#[actix_rt::test]
async fn get_task_status() {
    let server = Server::new_shared();
    let index = server.unique_index();
    let (create_task, _status_code) = index.create(None).await;
    let (add_task, _status_code) = index
        .add_documents(
            json!([{
                "id": 1,
                "content": "foobar",
            }]),
            None,
        )
        .await;
    index.wait_task(create_task.uid()).await.succeeded();
    let (_response, code) = index.get_task(add_task.uid()).await;
    assert_eq!(code, 200);
    // TODO check response format, as per #48
}

#[actix_rt::test]
async fn list_tasks() {
    let server = Server::new_shared();
    let index = server.unique_index();
    let (task, _status_code) = index.create(None).await;
    index.wait_task(task.uid()).await.succeeded();
    index
        .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None)
        .await;
    let (response, code) = index.list_tasks().await;
    assert_eq!(code, 200);
    assert_eq!(response["results"].as_array().unwrap().len(), 2);
}

#[actix_rt::test]
async fn list_tasks_pagination_and_reverse() {
    // do not use a shared server here, as we want to assert tasks ids and we need them to be stable
    let server = Server::new().await;
    // First of all we want to create a lot of tasks very quickly. The fastest way is to delete a lot of unexisting indexes
    let mut last_task = None;
    for i in 0..10 {
        let index = server.index(format!("test-{i}"));
        last_task = Some(index.create(None).await.0.uid());
    }
    server.wait_task(last_task.unwrap()).await.succeeded();

    let (response, code) = server.tasks_filter("limit=3").await;
    assert_eq!(code, 200);
    let results = response["results"].as_array().unwrap();

Review comment (suggestion):
```suggestion
    // Do not use a shared server because we want to assert stuff against the global list of tasks
    let server = Server::new().await;
    let index = server.index("test");
```

Code after:
#[actix_rt::test]
async fn get_task_status() {
    let server = Server::new_shared();
    let index = server.unique_index();
    let (create_task, _status_code) = index.create(None).await;
    let (add_task, _status_code) = index
        .add_documents(
            json!([{
                "id": 1,
                "content": "foobar",
            }]),
            None,
        )
        .await;
    index.wait_task(create_task.uid()).await.succeeded();
    let (_response, code) = index.get_task(add_task.uid()).await;
    assert_eq!(code, 200);
    // TODO check response format, as per #48
}

#[actix_rt::test]
async fn list_tasks() {
    // Do not use a shared server because we want to assert stuff against the global list of tasks
    let server = Server::new().await;
    let index = server.index("test");
    let (task, _status_code) = index.create(None).await;
    index.wait_task(task.uid()).await.succeeded();
    index
        .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None)
        .await;
    let (response, code) = index.list_tasks().await;
    assert_eq!(code, 200);
    assert_eq!(response["results"].as_array().unwrap().len(), 2);
}

#[actix_rt::test]
async fn list_tasks_pagination_and_reverse() {
    // do not use a shared server here, as we want to assert tasks ids and we need them to be stable
    let server = Server::new().await;
    // First of all we want to create a lot of tasks very quickly. The fastest way is to delete a lot of unexisting indexes
    let mut last_task = None;
    for i in 0..10 {
        let index = server.index(format!("test-{i}"));
        last_task = Some(index.create(None).await.0.uid());
    }
    server.wait_task(last_task.unwrap()).await.succeeded();

    let (response, code) = server.tasks_filter("limit=3").await;
    assert_eq!(code, 200);
    let results = response["results"].as_array().unwrap();
    let task_ids: Vec<_> = results.iter().map(|ret| ret["uid"].as_u64().unwrap()).collect();