Skip to content

Commit

Permalink
tests: Throw exception on upload async test.
Browse files Browse the repository at this point in the history
So that we know what exactly happened if there's a failure.
  • Loading branch information
amanda-tarafa committed Apr 19, 2024
1 parent 60d07e1 commit 3a3f8d5
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Grpc.Core.Interceptors;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Net;
using System.Net.Http;
Expand Down Expand Up @@ -97,14 +98,24 @@ public async Task UploadAsyncWithProgress()
var name = IdGenerator.FromGuid();
var contentType = "application/octet-stream";
var source = GenerateData(UploadObjectOptions.MinimumChunkSize * chunks);
int progressCount = 0;
var progress = new Progress<IUploadProgress>(p => progressCount++);
IList<IUploadProgress> progresses = new List<IUploadProgress>();
var progress = new Progress<IUploadProgress>(p => progresses.Add(p));
var result = await _fixture.Client.UploadObjectAsync(_fixture.MultiVersionBucket, name, contentType, source,
new UploadObjectOptions { ChunkSize = UploadObjectOptions.MinimumChunkSize },
CancellationToken.None, progress);
Assert.Equal(chunks + 1, progressCount); // Should start with a 0 progress

Assert.Collection(progresses,
first => CheckProgress(first, UploadStatus.Starting),
second => CheckProgress(second, UploadStatus.Uploading),
third => CheckProgress(third, UploadStatus.Completed));
Assert.Equal(name, result.Name); // Assume the rest of the properties are okay...
ValidateData(_fixture.MultiVersionBucket, name, source);

void CheckProgress(IUploadProgress progress, UploadStatus expectedStatus)
{
progress.ThrowOnFailure();
Assert.Equal(expectedStatus, progress.Status);
}
}

[Fact]
Expand Down

0 comments on commit 3a3f8d5

Please sign in to comment.