Skip to content

Commit 9ec66ae

Browse files
authored
[FR] Fix PercentageCompleted bug (Azure#24569)
1 parent 8ad561a commit 9ec66ae

File tree

9 files changed

+1337
-4
lines changed

9 files changed

+1337
-4
lines changed

sdk/formrecognizer/Azure.AI.FormRecognizer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Breaking Changes
88

99
### Bugs Fixed
10+
- `BuildModelOperation` and `CopyModelOperation` correctly populate the `PercentCompleted` property, instead of always having a value of `0`.
1011

1112
### Other Changes
1213

sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public BuildModelOperation(string operationId, Azure.AI.FormRecognizer.DocumentA
294294
public override bool HasCompleted { get { throw null; } }
295295
public override bool HasValue { get { throw null; } }
296296
public override string Id { get { throw null; } }
297-
public int PercentCompleted { get { throw null; } }
297+
public virtual int PercentCompleted { get { throw null; } }
298298
public override Azure.AI.FormRecognizer.DocumentAnalysis.DocumentModel Value { get { throw null; } }
299299
public override Azure.Response GetRawResponse() { throw null; }
300300
public override Azure.Response UpdateStatus(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
@@ -323,7 +323,7 @@ public CopyModelOperation(string operationId, Azure.AI.FormRecognizer.DocumentAn
323323
public override bool HasCompleted { get { throw null; } }
324324
public override bool HasValue { get { throw null; } }
325325
public override string Id { get { throw null; } }
326-
public int PercentCompleted { get { throw null; } }
326+
public virtual int PercentCompleted { get { throw null; } }
327327
public override Azure.AI.FormRecognizer.DocumentAnalysis.DocumentModel Value { get { throw null; } }
328328
public override Azure.Response GetRawResponse() { throw null; }
329329
public override Azure.Response UpdateStatus(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }

sdk/formrecognizer/Azure.AI.FormRecognizer/src/BuildModelOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class BuildModelOperation : Operation<DocumentModel>, IOperation<Document
3535
/// <summary>
3636
/// Gets the operation progress. Value is from [0-100].
3737
/// </summary>
38-
public int PercentCompleted => _percentCompleted;
38+
public virtual int PercentCompleted => _percentCompleted;
3939

4040
/// <summary>
4141
/// Final result of the long-running operation.

sdk/formrecognizer/Azure.AI.FormRecognizer/src/CopyModelOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class CopyModelOperation : Operation<DocumentModel>, IOperation<DocumentM
3535
/// <summary>
3636
/// Gets the operation progress. Value is from [0-100].
3737
/// </summary>
38-
public int PercentCompleted => _percentCompleted;
38+
public virtual int PercentCompleted => _percentCompleted;
3939

4040
/// <summary>
4141
/// Final result of the long-running operation.

sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentAnalysisModels/OperationsLiveTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ public async Task BuildModelOperationCanPollFromNewObject()
6262
Assert.AreEqual(modelId, sameOperation.Value.ModelId);
6363
}
6464

65+
[RecordedTest]
66+
public async Task BuildModelOperationPercentageCompletedValue()
67+
{
68+
var client = CreateDocumentModelAdministrationClient(out var nonInstrumentedClient);
69+
var trainingFilesUri = new Uri(TestEnvironment.BlobContainerSasUrl);
70+
var modelId = Recording.GenerateId();
71+
72+
var operation = await client.StartBuildModelAsync(trainingFilesUri, modelId);
73+
Assert.AreEqual(0, operation.PercentCompleted);
74+
75+
await operation.WaitForCompletionAsync();
76+
77+
Assert.IsTrue(operation.HasValue);
78+
Assert.AreEqual(100, operation.PercentCompleted);
79+
}
80+
6581
[RecordedTest]
6682
public async Task CopyModelOperationCanPollFromNewObject()
6783
{
@@ -81,5 +97,25 @@ public async Task CopyModelOperationCanPollFromNewObject()
8197
Assert.IsTrue(sameOperation.HasValue);
8298
Assert.AreEqual(targetModelId, sameOperation.Value.ModelId);
8399
}
100+
101+
[RecordedTest]
102+
public async Task CopyModelOperationPercentageCompletedValue()
103+
{
104+
var client = CreateDocumentModelAdministrationClient(out var nonInstrumentedClient);
105+
var modelId = Recording.GenerateId();
106+
107+
await using var trainedModel = await CreateDisposableBuildModelAsync(modelId);
108+
109+
var targetModelId = Recording.GenerateId();
110+
CopyAuthorization targetAuth = await client.GetCopyAuthorizationAsync(targetModelId);
111+
112+
var operation = await client.StartCopyModelAsync(trainedModel.ModelId, targetAuth);
113+
Assert.AreEqual(0, operation.PercentCompleted);
114+
115+
await operation.WaitForCompletionAsync();
116+
117+
Assert.IsTrue(operation.HasValue);
118+
Assert.AreEqual(100, operation.PercentCompleted);
119+
}
84120
}
85121
}

sdk/formrecognizer/Azure.AI.FormRecognizer/tests/SessionRecords/OperationsLiveTests/BuildModelOperationPercentageCompletedValue.json

Lines changed: 210 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)