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

Increase default task polling delay in order to avoid Paperless concurrency issues when creating documents #286

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/VMelnalksnis.PaperlessDotNet/PaperlessOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public sealed class PaperlessOptions

/// <summary> Gets or sets the time delay between each polling of tasks in milliseconds.</summary>
[Required]
public TimeSpan TaskPollingDelay { get; set; } = TimeSpan.FromMilliseconds(100);
public TimeSpan TaskPollingDelay { get; set; } = TimeSpan.FromMilliseconds(250);
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,44 @@ await FluentActions
.WithMessage("Response status code does not indicate success: 404 (Not Found).");
}

[Test]
public async Task CreateDuplicate()
{
if (PaperlessVersion < new Version(2, 0))
{
Assert.Ignore($"Paperless v{PaperlessVersion} does not directly allow downloading documents.");
}

const string documentName = "Lorem Ipsum.txt";

var tasks = Enumerable
.Range(1, 5)
.Select(_ =>
{
var stream = typeof(DocumentClientTests).GetResource(documentName);
var creation = new DocumentCreation(stream, documentName)
{
Created = Clock.GetCurrentInstant(),
Title = "Lorem Ipsum",
};

return Client.Documents.Create(creation);
});

var results = await Task.WhenAll(tasks);
var created = results.OfType<DocumentCreated>().Should().ContainSingle().Subject;

results
.Except([created])
.Should()
.AllBeOfType<ImportFailed>()
.Which.Should()
.AllSatisfy(failed =>
failed.Result.Should().Be($"{documentName}: Not consuming {documentName}: It is a duplicate of Lorem Ipsum (#{created.Id})"));

await Client.Documents.Delete(created.Id);
}

[Test]
public async Task Download()
{
Expand Down
Loading