Browse Source

Another test.

pull/945/head
Sebastian 4 years ago
parent
commit
30b362e1be
  1. 24
      backend/tools/TestSuite/TestSuite.ApiTests/AssetTests.cs

24
backend/tools/TestSuite/TestSuite.ApiTests/AssetTests.cs

@ -9,6 +9,7 @@ using System.Net;
using Squidex.Assets; using Squidex.Assets;
using Squidex.ClientLibrary.Management; using Squidex.ClientLibrary.Management;
using TestSuite.Fixtures; using TestSuite.Fixtures;
using Xunit.Sdk;
#pragma warning disable SA1300 // Element should begin with upper-case letter #pragma warning disable SA1300 // Element should begin with upper-case letter
#pragma warning disable SA1507 // Code should not contain multiple blank lines in a row #pragma warning disable SA1507 // Code should not contain multiple blank lines in a row
@ -71,7 +72,7 @@ public class AssetTests : IClassFixture<CreatedAppFixture>
[Fact] [Fact]
public async Task Should_upload_asset_using_tus_in_chunks() public async Task Should_upload_asset_using_tus_in_chunks()
{ {
for (var i = 0; i < 100; i++) for (var i = 0; i < 5; i++)
{ {
// STEP 1: Create asset // STEP 1: Create asset
progress = new ProgressHandler(); progress = new ProgressHandler();
@ -92,6 +93,8 @@ public class AssetTests : IClassFixture<CreatedAppFixture>
// When the previous request is still in progress we just give it another try. // When the previous request is still in progress we just give it another try.
if (progress.Exception is SquidexManagementException { StatusCode: 409 }) if (progress.Exception is SquidexManagementException { StatusCode: 409 })
{ {
progress.ResetException();
// Wait a little bit to finish the request on the server. // Wait a little bit to finish the request on the server.
await Task.Delay(100, cts.Token); await Task.Delay(100, cts.Token);
} }
@ -261,6 +264,8 @@ public class AssetTests : IClassFixture<CreatedAppFixture>
// When the previous request is still in progress we just give it another try. // When the previous request is still in progress we just give it another try.
if (progress.Exception is SquidexManagementException { StatusCode: 409 }) if (progress.Exception is SquidexManagementException { StatusCode: 409 })
{ {
progress.ResetException();
// Wait a little bit to finish the request on the server. // Wait a little bit to finish the request on the server.
await Task.Delay(100, cts.Token); await Task.Delay(100, cts.Token);
} }
@ -707,11 +712,16 @@ public class AssetTests : IClassFixture<CreatedAppFixture>
return options; return options;
} }
public void ResetException()
{
Exception = null;
}
public Task OnCompletedAsync(AssetUploadCompletedEvent @event, public Task OnCompletedAsync(AssetUploadCompletedEvent @event,
CancellationToken ct) CancellationToken ct)
{ {
// This is a previous exception, so we can unset it. // This is a previous exception, so we can unset it.
Exception = null; ResetException();
Asset = @event.Asset; Asset = @event.Asset;
return Task.CompletedTask; return Task.CompletedTask;
@ -734,7 +744,7 @@ public class AssetTests : IClassFixture<CreatedAppFixture>
public Task OnFailedAsync(AssetUploadExceptionEvent @event, public Task OnFailedAsync(AssetUploadExceptionEvent @event,
CancellationToken ct) CancellationToken ct)
{ {
if (!@event.Exception.ToString().Contains("PAUSED", StringComparison.OrdinalIgnoreCase)) if (@event.Exception.InnerException is not PauseException)
{ {
Exception = @event.Exception; Exception = @event.Exception;
} }
@ -743,7 +753,11 @@ public class AssetTests : IClassFixture<CreatedAppFixture>
} }
} }
public class PauseStream : DelegateStream private sealed class PauseException : Exception
{
}
private sealed class PauseStream : DelegateStream
{ {
private readonly double pauseAfter = 1; private readonly double pauseAfter = 1;
private int totalRead; private int totalRead;
@ -764,7 +778,7 @@ public class AssetTests : IClassFixture<CreatedAppFixture>
{ {
if (totalRead > Length * pauseAfter) if (totalRead > Length * pauseAfter)
{ {
throw new InvalidOperationException("PAUSED"); throw new PauseException();
} }
var bytesRead = await base.ReadAsync(buffer, cancellationToken); var bytesRead = await base.ReadAsync(buffer, cancellationToken);

Loading…
Cancel
Save