add tests for the task deletion and task cancelation

This commit is contained in:
Irevoire 2022-10-26 11:23:51 +02:00 committed by Clément Renault
parent a85d5b4981
commit 033794d209
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
2 changed files with 42 additions and 13 deletions

View File

@ -156,6 +156,10 @@ impl Server {
.await .await
} }
pub async fn delete_task(&self, value: Value) -> (Value, StatusCode) {
self.service.delete(format!("/tasks?{}", yaup::to_string(&value).unwrap())).await
}
pub async fn wait_task(&self, update_id: u64) -> Value { pub async fn wait_task(&self, update_id: u64) -> Value {
// try several times to get status, or panic to not wait forever // try several times to get status, or panic to not wait forever
let url = format!("/tasks/{}", update_id); let url = format!("/tasks/{}", update_id);

View File

@ -750,40 +750,65 @@ async fn test_summarized_index_swap() {
} }
#[actix_web::test] #[actix_web::test]
#[ignore]
async fn test_summarized_task_cancelation() { async fn test_summarized_task_cancelation() {
let server = Server::new().await; let server = Server::new().await;
let index = server.index("doggos"); let index = server.index("doggos");
// to avoid being flaky we're only going to test to cancel an already finished task :( // to avoid being flaky we're only going to cancel an already finished task :(
index.create(None).await; index.create(None).await;
index.wait_task(0).await; index.wait_task(0).await;
let (ret, code) = server.cancel_task(json!({ "uid": [0] })).await; server.cancel_task(json!({ "uid": [0] })).await;
dbg!(ret, code);
index.wait_task(1).await; index.wait_task(1).await;
let (task, _) = index.get_task(1).await; let (task, _) = index.get_task(1).await;
assert_json_snapshot!(task, assert_json_snapshot!(task,
{ ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" },
@r###" @r###"
{ {
"uid": 0, "uid": 1,
"indexUid": "test", "indexUid": null,
"status": "succeeded", "status": "succeeded",
"type": "indexCreation", "type": "taskCancelation",
"details": { "details": {
"primaryKey": null "matchedTasks": 1,
"canceledTasks": 0,
"originalQuery": "uid=0"
}, },
"duration": "PT0.002782S", "duration": "[duration]",
"enqueuedAt": "2022-10-25T15:23:26.898722Z", "enqueuedAt": "[date]",
"startedAt": "2022-10-25T15:23:26.90063Z", "startedAt": "[date]",
"finishedAt": "2022-10-25T15:23:26.903412Z" "finishedAt": "[date]"
} }
"###); "###);
} }
#[actix_web::test] #[actix_web::test]
#[ignore]
async fn test_summarized_task_deletion() { async fn test_summarized_task_deletion() {
let server = Server::new().await; let server = Server::new().await;
let index = server.index("doggos");
// to avoid being flaky we're only going to delete an already finished task :(
index.create(None).await;
index.wait_task(0).await;
server.delete_task(json!({ "uid": [0] })).await;
index.wait_task(1).await;
let (task, _) = index.get_task(1).await;
assert_json_snapshot!(task,
{ ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" },
@r###"
{
"uid": 1,
"indexUid": null,
"status": "succeeded",
"type": "taskDeletion",
"details": {
"matchedTasks": 1,
"deletedTasks": 1,
"originalQuery": "uid=0"
},
"duration": "[duration]",
"enqueuedAt": "[date]",
"startedAt": "[date]",
"finishedAt": "[date]"
}
"###);
} }