Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Unknown type to TaskInfoType #542

Merged
merged 14 commits into from
Aug 5, 2024
18 changes: 18 additions & 0 deletions src/Meilisearch/MeilisearchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,5 +425,23 @@ private TaskEndpoint TaskEndpoint()

return _taskEndpoint;
}


public async Task<TaskInfo> CreateUnknownTaskAsync(UnknownTaskQuery query, CancellationToken cancellationToken = default)
{
var response = await _http.PostAsJsonAsync("create-unknown-task", query, Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken)
.ConfigureAwait(false);

return await response.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken).ConfigureAwait(false);
}

public async Task<TaskInfo> GetTaskWithUnknownTypeAsync(GetTaskQuery query, CancellationToken cancellationToken = default)
{
var response = await _http.PostAsJsonAsync("get-task-with-unknown-type", query, Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken)
.ConfigureAwait(false);

return await response.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken).ConfigureAwait(false);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of these are unnecessary

}
}
12 changes: 12 additions & 0 deletions src/Meilisearch/QueryParameters/GetTaskQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this new file is unnecessary

using System.Collections.Generic;
using System.Text;

namespace Meilisearch.QueryParameters
{
public class GetTaskQuery
{
public Guid Uid { get; set; }
}

}
13 changes: 13 additions & 0 deletions src/Meilisearch/QueryParameters/UnknownTaskQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this new file is unnecessary

using System.Collections.Generic;
using System.Text;

namespace Meilisearch.QueryParameters
{
public class UnknownTaskQuery
{
public Guid Uid { get; set; }
public TaskInfoType TaskType { get; set; }
}

}
3 changes: 2 additions & 1 deletion src/Meilisearch/TaskInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public enum TaskInfoType
TaskCancelation,
SnapshotCreation,
TaskDeletion,
IndexSwap
IndexSwap,
Unknown
}
}
37 changes: 37 additions & 0 deletions tests/Meilisearch.Tests/MeilisearchClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,43 @@ public async Task SwapIndexes()
Assert.Equal(task.Details["swaps"].ToString(), JsonSerializer.Serialize(swaps).ToString());
}

[Fact]
public async Task HandleUnknownTaskType()
{
// Simulate an unknown task type response
var unknownTaskUid = Guid.NewGuid();
var response = await _defaultClient.CreateUnknownTaskAsync(new UnknownTaskQuery
{
Uid = unknownTaskUid,
TaskType = TaskInfoType.Unknown
});
var task = await _defaultClient.WaitForTaskAsync(response.TaskUid);

response.TaskUid.Should().Be(task.Uid);
response.Type.Should().Be(TaskInfoType.Unknown);
task.Status.Should().Be(TaskInfoStatus.Failed);
Assert.Equal($"?uid={unknownTaskUid}", task.Details["originalFilter"].ToString());
}


[Fact]
public async Task GracefulHandlingOfUnknownTaskType()
{
// Simulate receiving a task with an unknown type
var unknownTaskUid = Guid.NewGuid();
var response = await _defaultClient.GetTaskWithUnknownTypeAsync(new GetTaskQuery
{
Uid = unknownTaskUid
});
var task = await _defaultClient.WaitForTaskAsync(response.TaskUid);

response.TaskUid.Should().Be(task.Uid);
response.Type.Should().Be(TaskInfoType.Unknown);
task.Status.Should().Be(TaskInfoStatus.Failed);
Assert.Equal($"?uid={unknownTaskUid}", task.Details["originalFilter"].ToString());
}


[Fact]
public async Task Health()
{
Expand Down
Loading