Skip to content

Commit

Permalink
Fixes integration tests hanging on CreateIfNotExistsAsync and DeleteI…
Browse files Browse the repository at this point in the history
…fExistsAsync (Azure#15719)

* Fixes a few integration tests.

* Cleanup.

* More cleanup.

* More cleanup.

* Fixed a test broken in the previous PR.

* Made test synchronous.

* Fixes file access problem.
  • Loading branch information
paterasMSFT authored and suhas92 committed Oct 12, 2020
1 parent 0271222 commit 17736b7
Show file tree
Hide file tree
Showing 58 changed files with 7,055 additions and 7,570 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ internal static bool ShouldRetry(Exception exception, OperationContext operation

if (currentRetryCount < maxRetries)
{
BatchException batchException = exception as BatchException;
if (batchException != null)
if (exception is BatchException batchException)
{
int statusCode = (int)batchException.RequestInformation.HttpStatusCode;

if ((statusCode >= 400 && statusCode < 500
if ((statusCode >= 400 && statusCode < 500
&& statusCode != 408 // Timeout
&& statusCode != 429 // Too many reqeuests
)
Expand Down
118 changes: 59 additions & 59 deletions sdk/batch/Microsoft.Azure.Batch/src/JobOperations.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ namespace Microsoft.Azure.Batch.IntegrationTestCommon.Tests.Helpers
/// </summary>
class CertificateCredentialsNetCore : ServiceClientCredentials
{
private X509Certificate2 cert;
private readonly X509Certificate2 cert;
public CertificateCredentialsNetCore(X509Certificate2 cert)
{
this.cert = cert;
}
public override void InitializeServiceClient<T>(ServiceClient<T> client)
{
HttpClientHandler handler = client.HttpMessageHandlers.FirstOrDefault(h => h is HttpClientHandler) as HttpClientHandler;
handler.ClientCertificates.Add(this.cert);
handler.ClientCertificates.Add(cert);
}
}
#endif
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,41 @@ public static async Task UploadTestApplicationPackageIfNotAlreadyUploadedAsync(
string accountName,
string resourceGroupName)
{
using (BatchManagementClient mgmtClient = IntegrationTestCommon.OpenBatchManagementClient())
{
IPage<Application> applicationSummaries =
await mgmtClient.Application.ListAsync(resourceGroupName, accountName).ConfigureAwait(false);
using BatchManagementClient mgmtClient = IntegrationTestCommon.OpenBatchManagementClient();
IPage<Application> applicationSummaries =
await mgmtClient.Application.ListAsync(resourceGroupName, accountName).ConfigureAwait(false);

bool testPackageAlreadyUploaded =
applicationSummaries.Any(a => string.Equals(appPackageName, a.Id, StringComparison.OrdinalIgnoreCase));
bool testPackageAlreadyUploaded =
applicationSummaries.Any(a => string.Equals(appPackageName, a.Id, StringComparison.OrdinalIgnoreCase));

if (!testPackageAlreadyUploaded)
{
const string format = "zip";
if (!testPackageAlreadyUploaded)
{
const string format = "zip";

var addResponse =
await
mgmtClient.ApplicationPackage.CreateAsync(resourceGroupName, accountName, appPackageName, applicationVersion)
.ConfigureAwait(false);
var storageUrl = addResponse.StorageUrl;
var addResponse =
await
mgmtClient.ApplicationPackage.CreateAsync(resourceGroupName, accountName, appPackageName, applicationVersion)
.ConfigureAwait(false);
var storageUrl = addResponse.StorageUrl;

await IntegrationTestCommon.UploadTestApplicationAsync(storageUrl).ConfigureAwait(false);
await IntegrationTestCommon.UploadTestApplicationAsync(storageUrl).ConfigureAwait(false);

await
mgmtClient.ApplicationPackage.ActivateAsync(
resourceGroupName,
accountName,
appPackageName,
applicationVersion,
format).ConfigureAwait(false);
}
await
mgmtClient.ApplicationPackage.ActivateAsync(
resourceGroupName,
accountName,
appPackageName,
applicationVersion,
format).ConfigureAwait(false);
}
}

public static async Task DeleteApplicationAsync(string applicationPackage, string resourceGroupName, string accountName)
{
using (BatchManagementClient mgmtClient = IntegrationTestCommon.OpenBatchManagementClient())
{
await mgmtClient.ApplicationPackage.DeleteAsync(resourceGroupName, accountName, applicationPackage, Version).ConfigureAwait(false);
using BatchManagementClient mgmtClient = IntegrationTestCommon.OpenBatchManagementClient();
await mgmtClient.ApplicationPackage.DeleteAsync(resourceGroupName, accountName, applicationPackage, Version).ConfigureAwait(false);

await mgmtClient.Application.DeleteAsync(resourceGroupName, accountName, applicationPackage).ConfigureAwait(false);
}
await mgmtClient.Application.DeleteAsync(resourceGroupName, accountName, applicationPackage).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,50 +43,46 @@ public async Task End2EndApplicationPackageScenario()
Func<Task> test = async () =>
{
var poolId = "app-ref-test" + Guid.NewGuid();
using (BatchClient client = await TestUtilities.OpenBatchClientFromEnvironmentAsync())
using BatchClient client = await TestUtilities.OpenBatchClientFromEnvironmentAsync();
using var mgmtClient = IntegrationTestCommon.OpenBatchManagementClient();
// Give the application a display name
await mgmtClient.Application.UpdateAsync(TestCommon.Configuration.BatchAccountResourceGroup, accountName, ApplicationId, new UpdateApplicationParameters
{
using (var mgmtClient = IntegrationTestCommon.OpenBatchManagementClient())
{
// Give the application a display name
await mgmtClient.Application.UpdateAsync(TestCommon.Configuration.BatchAccountResourceGroup, accountName, ApplicationId, new UpdateApplicationParameters
{
AllowUpdates = true,
DefaultVersion = ApplicationIntegrationCommon.Version,
DisplayName = DisplayName
}).ConfigureAwait(false);
AllowUpdates = true,
DefaultVersion = ApplicationIntegrationCommon.Version,
DisplayName = DisplayName
}).ConfigureAwait(false);
List<ApplicationSummary> applicationSummaries = await client.ApplicationOperations.ListApplicationSummaries().ToListAsync().ConfigureAwait(false);
List<ApplicationSummary> applicationSummaries = await client.ApplicationOperations.ListApplicationSummaries().ToListAsync().ConfigureAwait(false);
ApplicationSummary applicationSummary = applicationSummaries.First();
Assert.Equal(ApplicationIntegrationCommon.Version, applicationSummary.Versions.First());
Assert.Equal(ApplicationId, applicationSummary.Id);
Assert.Equal(DisplayName, applicationSummary.DisplayName);
ApplicationSummary applicationSummary = applicationSummaries.First();
Assert.Equal(ApplicationIntegrationCommon.Version, applicationSummary.Versions.First());
Assert.Equal(ApplicationId, applicationSummary.Id);
Assert.Equal(DisplayName, applicationSummary.DisplayName);
ApplicationSummary getApplicationSummary = await client.ApplicationOperations.GetApplicationSummaryAsync(applicationSummary.Id).ConfigureAwait(false);
ApplicationSummary getApplicationSummary = await client.ApplicationOperations.GetApplicationSummaryAsync(applicationSummary.Id).ConfigureAwait(false);
Assert.Equal(getApplicationSummary.Id, applicationSummary.Id);
Assert.Equal(getApplicationSummary.Versions.Count(), applicationSummary.Versions.Count());
Assert.Equal(getApplicationSummary.DisplayName, applicationSummary.DisplayName);
Assert.Equal(getApplicationSummary.Id, applicationSummary.Id);
Assert.Equal(getApplicationSummary.Versions.Count(), applicationSummary.Versions.Count());
Assert.Equal(getApplicationSummary.DisplayName, applicationSummary.DisplayName);
var appPackage = await mgmtClient.ApplicationPackage.GetAsync(
TestCommon.Configuration.BatchAccountResourceGroup,
accountName,
ApplicationId,
ApplicationIntegrationCommon.Version).ConfigureAwait(false);
var appPackage = await mgmtClient.ApplicationPackage.GetAsync(
TestCommon.Configuration.BatchAccountResourceGroup,
accountName,
ApplicationId,
ApplicationIntegrationCommon.Version).ConfigureAwait(false);
Assert.Equal(PackageState.Active, appPackage.State);
Assert.Equal(ApplicationIntegrationCommon.Version, appPackage.Version);
Assert.Equal(ApplicationId, appPackage.Id);
Assert.Equal(PackageState.Active, appPackage.State);
Assert.Equal(ApplicationIntegrationCommon.Version, appPackage.Version);
Assert.Equal(ApplicationId, appPackage.Id);
var application = await mgmtClient.Application.GetAsync(TestCommon.Configuration.BatchAccountResourceGroup, accountName, ApplicationId).ConfigureAwait(false);
var application = await mgmtClient.Application.GetAsync(TestCommon.Configuration.BatchAccountResourceGroup, accountName, ApplicationId).ConfigureAwait(false);
Assert.Equal(ApplicationIntegrationCommon.Version, application.DefaultVersion);
Assert.Equal(ApplicationId, application.Id);
Assert.Equal(ApplicationIntegrationCommon.Version, application.DefaultVersion);
Assert.Equal(ApplicationId, application.Id);
await AssertPoolWasCreatedWithApplicationReferences(client, poolId, ApplicationId).ConfigureAwait(false);
}
}
await AssertPoolWasCreatedWithApplicationReferences(client, poolId, ApplicationId).ConfigureAwait(false);
};

await SynchronizationContextHelper.RunTestAsync(test, LongRunningTestTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,17 @@ public async Task IfThereAreApplicationsInTheAccountThenListApplicationSummaries
{
Func<Task> test = async () =>
{
using (BatchClient client = await TestUtilities.OpenBatchClientFromEnvironmentAsync().ConfigureAwait(false))
{
List<ApplicationSummary> applicationSummaries = await client.ApplicationOperations.ListApplicationSummaries().ToListAsync().ConfigureAwait(false);
var application = applicationSummaries.First(app => app.Id == ApplicationId);
using BatchClient client = await TestUtilities.OpenBatchClientFromEnvironmentAsync().ConfigureAwait(false);
List<ApplicationSummary> applicationSummaries = await client.ApplicationOperations.ListApplicationSummaries().ToListAsync().ConfigureAwait(false);
var application = applicationSummaries.First(app => app.Id == ApplicationId);
Assert.Equal(ApplicationId, application.Id);
Assert.Equal(ApplicationIntegrationCommon.Version, application.Versions.FirstOrDefault());
Assert.Equal(ApplicationId, application.Id);
Assert.Equal(ApplicationIntegrationCommon.Version, application.Versions.FirstOrDefault());
ApplicationSummary getApplicationSummary = await client.ApplicationOperations.GetApplicationSummaryAsync(application.Id).ConfigureAwait(false);
ApplicationSummary getApplicationSummary = await client.ApplicationOperations.GetApplicationSummaryAsync(application.Id).ConfigureAwait(false);
Assert.Equal(ApplicationId, getApplicationSummary.Id);
Assert.Equal(ApplicationIntegrationCommon.Version, getApplicationSummary.Versions.First());
}
Assert.Equal(ApplicationId, getApplicationSummary.Id);
Assert.Equal(ApplicationIntegrationCommon.Version, getApplicationSummary.Versions.First());
};

await SynchronizationContextHelper.RunTestAsync(test, TestTimeout);
Expand Down
Loading

0 comments on commit 17736b7

Please sign in to comment.