Skip to content

Commit

Permalink
fix: Increase default task polling delay in order to avoid Paperless …
Browse files Browse the repository at this point in the history
…concurrency issues when creating documents
  • Loading branch information
VMelnalksnis committed Dec 18, 2024
1 parent 5ed0760 commit a810ef6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
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

0 comments on commit a810ef6

Please sign in to comment.