|
3 | 3 |
|
4 | 4 | using System; |
5 | 5 | using System.Collections.Generic; |
6 | | -using System.Linq; |
7 | 6 | using System.Threading; |
8 | 7 | using System.Threading.Tasks; |
9 | 8 | using Azure.Core.TestFramework; |
@@ -80,21 +79,42 @@ public async Task WaitForCompletionWaitsDuringLive() |
80 | 79 | Assert.AreEqual(TimeSpan.FromSeconds(10), original.WaitForCompletionCalls[3]); |
81 | 80 | } |
82 | 81 |
|
| 82 | + [Test] |
| 83 | + public async Task WaitForCompletionErrorsArePropagated() |
| 84 | + { |
| 85 | + var client = InstrumentClient(new RecordedClient()); |
| 86 | + |
| 87 | + var operation = await client.StartOperationAsync(true); |
| 88 | + |
| 89 | + Assert.ThrowsAsync<RequestFailedException>(async () => await operation.WaitForCompletionAsync()); |
| 90 | + } |
| 91 | + |
83 | 92 | public class RecordedClient |
84 | 93 | { |
85 | | - public virtual Task<CustomOperation> StartOperationAsync() |
| 94 | + public virtual Task<CustomOperation> StartOperationAsync(bool throwOnWait = false) |
86 | 95 | { |
87 | | - return Task.FromResult(new CustomOperation()); |
| 96 | + return Task.FromResult(new CustomOperation(throwOnWait)); |
88 | 97 | } |
89 | 98 |
|
90 | | - public virtual CustomOperation StartOperation() |
| 99 | + public virtual CustomOperation StartOperation(bool throwOnWait = false) |
91 | 100 | { |
92 | | - return new CustomOperation(); |
| 101 | + return new CustomOperation(throwOnWait); |
93 | 102 | } |
94 | 103 | } |
95 | 104 |
|
96 | 105 | public class CustomOperation : Operation<int> |
97 | 106 | { |
| 107 | + private readonly bool _throwOnWait; |
| 108 | + |
| 109 | + public CustomOperation(bool throwOnWait) |
| 110 | + { |
| 111 | + _throwOnWait = throwOnWait; |
| 112 | + } |
| 113 | + |
| 114 | + protected CustomOperation() |
| 115 | + { |
| 116 | + } |
| 117 | + |
98 | 118 | public virtual List<TimeSpan?> WaitForCompletionCalls { get; } = new(); |
99 | 119 | public override string Id { get; } |
100 | 120 | public override Response GetRawResponse() |
@@ -123,6 +143,10 @@ public override ValueTask<Response<int>> WaitForCompletionAsync(CancellationToke |
123 | 143 | public override ValueTask<Response<int>> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken) |
124 | 144 | { |
125 | 145 | WaitForCompletionCalls.Add(pollingInterval); |
| 146 | + if (_throwOnWait) |
| 147 | + { |
| 148 | + throw new RequestFailedException(400, "Operation failed"); |
| 149 | + } |
126 | 150 | return new(Response.FromValue(0, new MockResponse(200))); |
127 | 151 | } |
128 | 152 | } |
|
0 commit comments