Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task FormRecognizerClientCanAuthenticateWithTokenCredential()

// Sanity check to make sure we got an actual response back from the service.

FormPageCollection formPages = await operation.WaitForCompletionAsync();
FormPageCollection formPages = await operation.WaitForCompletionAsync(PollingInterval);
var formPage = formPages.Single();

Assert.Greater(formPage.Lines.Count, 0);
Expand Down Expand Up @@ -101,7 +101,7 @@ public async Task StartRecognizeContentPopulatesFormPage(bool useStream)
operation = await client.StartRecognizeContentFromUriAsync(uri);
}

await operation.WaitForCompletionAsync();
await operation.WaitForCompletionAsync(PollingInterval);
Assert.IsTrue(operation.HasValue);

var formPage = operation.Value.Single();
Expand Down Expand Up @@ -193,7 +193,7 @@ public async Task StartRecognizeContentCanParseMultipageForm(bool useStream)
operation = await client.StartRecognizeContentFromUriAsync(uri);
}

FormPageCollection formPages = await operation.WaitForCompletionAsync();
FormPageCollection formPages = await operation.WaitForCompletionAsync(PollingInterval);

Assert.AreEqual(2, formPages.Count);

Expand Down Expand Up @@ -224,7 +224,7 @@ public async Task StartRecognizeContentCanParseMultipageFormWithBlankPage()
operation = await client.StartRecognizeContentAsync(stream);
}

FormPageCollection formPages = await operation.WaitForCompletionAsync();
FormPageCollection formPages = await operation.WaitForCompletionAsync(PollingInterval);

Assert.AreEqual(3, formPages.Count);

Expand Down Expand Up @@ -290,7 +290,7 @@ public async Task StartRecognizeReceiptsPopulatesExtractedReceipt(bool useStream
operation = await client.StartRecognizeReceiptsFromUriAsync(uri, default);
}

await operation.WaitForCompletionAsync();
await operation.WaitForCompletionAsync(PollingInterval);

Assert.IsTrue(operation.HasValue);

Expand Down Expand Up @@ -397,7 +397,7 @@ public async Task StartRecognizeReceiptsCanParseMultipageForm(bool useStream)
operation = await client.StartRecognizeReceiptsFromUriAsync(uri, options);
}

RecognizedReceiptCollection recognizedReceipts = await operation.WaitForCompletionAsync();
RecognizedReceiptCollection recognizedReceipts = await operation.WaitForCompletionAsync(PollingInterval);

Assert.AreEqual(2, recognizedReceipts.Count);

Expand Down Expand Up @@ -434,7 +434,7 @@ public async Task StartRecognizeReceiptsCanParseMultipageFormWithBlankPage()
operation = await client.StartRecognizeReceiptsAsync(stream, options);
}

RecognizedReceiptCollection recognizedReceipts = await operation.WaitForCompletionAsync();
RecognizedReceiptCollection recognizedReceipts = await operation.WaitForCompletionAsync(PollingInterval);

Assert.AreEqual(3, recognizedReceipts.Count);

Expand Down Expand Up @@ -511,7 +511,7 @@ public async Task StartRecognizeCustomFormsWithLabels(bool useStream)
operation = await client.StartRecognizeCustomFormsFromUriAsync(trainedModel.ModelId, uri);
}

await operation.WaitForCompletionAsync();
await operation.WaitForCompletionAsync(PollingInterval);

Assert.IsTrue(operation.HasValue);
Assert.GreaterOrEqual(operation.Value.Count, 1);
Expand Down Expand Up @@ -561,7 +561,7 @@ public async Task StartRecognizeCustomFormsWithLabelsCanParseMultipageForm(bool
operation = await client.StartRecognizeCustomFormsFromUriAsync(trainedModel.ModelId, uri, options);
}

RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync();
RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync(PollingInterval);

var recognizedForm = recognizedForms.Single();

Expand Down Expand Up @@ -598,7 +598,7 @@ public async Task StartRecognizeCustomFormsWithLabelsCanParseBlankPage()
operation = await client.StartRecognizeCustomFormsAsync(trainedModel.ModelId, stream, options);
}

RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync();
RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync(PollingInterval);

var recognizedForm = recognizedForms.Single();

Expand Down Expand Up @@ -626,7 +626,7 @@ public async Task StartRecognizeCustomFormsWithLabelsCanParseMultipageFormWithBl
operation = await client.StartRecognizeCustomFormsAsync(trainedModel.ModelId, stream, options);
}

RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync();
RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync(PollingInterval);

var recognizedForm = recognizedForms.Single();

Expand Down Expand Up @@ -670,7 +670,7 @@ public async Task StartRecognizeCustomFormsWithLabelsCanParseDifferentTypeOfForm
operation = await client.StartRecognizeCustomFormsAsync(trainedModel.ModelId, stream);
}

RecognizedFormCollection forms = await operation.WaitForCompletionAsync();
RecognizedFormCollection forms = await operation.WaitForCompletionAsync(PollingInterval);
var fields = forms.Single().Fields;

// Verify that we got back at least one null field to make sure we hit the code path we want to test.
Expand Down Expand Up @@ -706,7 +706,7 @@ public async Task StartRecognizeCustomFormsWithoutLabels(bool useStream)
operation = await client.StartRecognizeCustomFormsFromUriAsync(trainedModel.ModelId, uri);
}

await operation.WaitForCompletionAsync();
await operation.WaitForCompletionAsync(PollingInterval);

Assert.IsTrue(operation.HasValue);
Assert.GreaterOrEqual(operation.Value.Count, 1);
Expand Down Expand Up @@ -757,7 +757,7 @@ public async Task StartRecognizeCustomFormsWithoutLabelsCanParseMultipageForm(bo
operation = await client.StartRecognizeCustomFormsFromUriAsync(trainedModel.ModelId, uri, options);
}

RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync();
RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync(PollingInterval);

Assert.AreEqual(2, recognizedForms.Count);

Expand Down Expand Up @@ -797,7 +797,7 @@ public async Task StartRecognizeCustomFormsWithoutLabelsCanParseMultipageFormWit
operation = await client.StartRecognizeCustomFormsAsync(trainedModel.ModelId, stream, options);
}

RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync();
RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync(PollingInterval);

Assert.AreEqual(3, recognizedForms.Count);

Expand Down Expand Up @@ -852,7 +852,7 @@ public async Task StartRecognizeCustomFormsFromUriThrowsForNonExistingContent(bo

try
{
await operation.WaitForCompletionAsync();
await operation.WaitForCompletionAsync(PollingInterval);
}
catch (RequestFailedException ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task FormTrainingClientCanAuthenticateWithTokenCredential()

// Sanity check to make sure we got an actual response back from the service.

CustomFormModel model = await operation.WaitForCompletionAsync();
CustomFormModel model = await operation.WaitForCompletionAsync(PollingInterval);

Assert.IsNotNull(model.ModelId);
Assert.AreEqual(CustomFormModelStatus.Ready, model.Status);
Expand All @@ -65,7 +65,7 @@ public async Task StartTraining(bool labeled)
operation = await client.StartTrainingAsync(trainingFilesUri, labeled);
}

await operation.WaitForCompletionAsync();
await operation.WaitForCompletionAsync(PollingInterval);

Assert.IsTrue(operation.HasValue);

Expand Down Expand Up @@ -109,7 +109,7 @@ public async Task StartTrainingError()
var containerUrl = new Uri("https://someUrl");

TrainingOperation operation = await client.StartTrainingAsync(containerUrl, useTrainingLabels: false);
Assert.ThrowsAsync<RequestFailedException>(async () => await operation.WaitForCompletionAsync());
Assert.ThrowsAsync<RequestFailedException>(async () => await operation.WaitForCompletionAsync(PollingInterval));

Assert.False(operation.HasValue);
Assert.Throws<RequestFailedException>(() => operation.Value.GetType());
Expand All @@ -130,7 +130,7 @@ public async Task TrainingOps(bool labeled)
operation = await client.StartTrainingAsync(trainingFilesUri, labeled);
}

await operation.WaitForCompletionAsync();
await operation.WaitForCompletionAsync(PollingInterval);

Assert.IsTrue(operation.HasValue);

Expand Down Expand Up @@ -207,7 +207,7 @@ public async Task CopyModel()
operation = await sourceClient.StartCopyModelAsync(trainedModel.ModelId, targetAuth);
}

await operation.WaitForCompletionAsync();
await operation.WaitForCompletionAsync(PollingInterval);
Assert.IsTrue(operation.HasValue);

CustomFormModelInfo modelCopied = operation.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ private DisposableTrainedModel(FormTrainingClient trainingClient, string modelId
/// <param name="trainingFilesUri">An externally accessible Azure storage blob container Uri.</param>
/// <param name="useTrainingLabels">If <c>true</c>, use a label file created in the &lt;link-to-label-tool-doc&gt; to provide training-time labels for training a model. If <c>false</c>, the model will be trained from forms only.</param>
/// <returns>A <see cref="DisposableTrainedModel"/> instance from which the trained model ID can be obtained.</returns>
public static async Task<DisposableTrainedModel> TrainModelAsync(FormTrainingClient trainingClient, Uri trainingFilesUri, bool useTrainingLabels)
public static async Task<DisposableTrainedModel> TrainModelAsync(FormTrainingClient trainingClient, Uri trainingFilesUri, bool useTrainingLabels, TimeSpan pollingInterval)
{
TrainingOperation operation = await trainingClient.StartTrainingAsync(trainingFilesUri, useTrainingLabels);
await operation.WaitForCompletionAsync();
await operation.WaitForCompletionAsync(pollingInterval);

Assert.IsTrue(operation.HasValue);
Assert.AreEqual(CustomFormModelStatus.Ready, operation.Value.Status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Azure.AI.FormRecognizer.Tests
{
public class FormRecognizerLiveTestBase : RecordedTestBase<FormRecognizerTestEnvironment>
{
protected TimeSpan PollingInterval => TimeSpan.FromSeconds(Mode == RecordedTestMode.Playback ? 0 : 1);

public FormRecognizerLiveTestBase(bool isAsync) : base(isAsync)
{
Sanitizer = new FormRecognizerRecordedTestSanitizer();
Expand Down Expand Up @@ -58,7 +60,7 @@ protected async Task<DisposableTrainedModel> CreateDisposableTrainedModelAsync(b
// TODO: sanitize body and enable body recording here.
using (Recording.DisableRequestBodyRecording())
{
trainedModel = await DisposableTrainedModel.TrainModelAsync(trainingClient, trainingFilesUri, useTrainingLabels);
trainedModel = await DisposableTrainedModel.TrainModelAsync(trainingClient, trainingFilesUri, useTrainingLabels, PollingInterval);
}

return trainedModel;
Expand Down
Loading