Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address flaky unit tests #817

Merged
merged 1 commit into from
Nov 11, 2024
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
2 changes: 1 addition & 1 deletion src/CommonUtilities.Tests/ArmEnvironmentEndpointsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CommonUtilities.Tests
{
[TestClass]
[TestClass, TestCategory("Integration")]
public class ArmEnvironmentEndpointsTests
{
public enum Cloud
Expand Down
29 changes: 29 additions & 0 deletions src/CommonUtilities/AzureCloudConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,35 @@ public static Task<AzureCloudConfig> FromKnownCloudNameAsync(string cloudName =
};
}

public static AzureCloudConfig ForUnitTesting()
{
return new()
{
PortalUrl = "http://portal.test",
Authentication = new() { Tenant = "common" },
MediaUrl = "http://media.test",
GraphAudienceUrl = "http://graph.test",
Name = "Test",
Suffixes = new()
{
AcrLoginServerSuffix = "azurecr.io",
KeyVaultDnsSuffix = "vault.azure.net",
StorageSuffix = "core.windows.net",
PostgresqlServerEndpointSuffix = "postgres.database.azure.com"
},
BatchUrl = "https://batch.core.windows.net/",
ResourceManagerUrl = "https://management.azure.com/",
MicrosoftGraphResourceUrl = "http://graph.test",
ApplicationInsightsResourceUrl = "https://api.applicationinsights.io",
ApplicationInsightsTelemetryChannelResourceUrl = "https://dc.applicationinsights.azure.com/v2/track",

DefaultTokenScope = "https://management.azure.com//.default",
ArmEnvironment = new(new("https://management.azure.com/"), "https://management.azure.com/"),
Domain = "Test",
AzureEnvironmentConfig = new("https://login.microsoftonline.com", "https://management.azure.com//.default", "core.windows.net")
};
}

private static readonly Uri AzurePublicCloud = Azure.ResourceManager.ArmEnvironment.AzurePublicCloud.Endpoint;
private static readonly Uri AzureUSGovernmentCloud = Azure.ResourceManager.ArmEnvironment.AzureGovernment.Endpoint;
private static readonly Uri AzureChinaCloud = Azure.ResourceManager.ArmEnvironment.AzureChina.Endpoint;
Expand Down
15 changes: 0 additions & 15 deletions src/CommonUtilities/ExpensiveObjectTestUtility.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Tes.ApiClients.Tests/TerraSamApiClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void SetUp()
cache.Setup(c => c.CreateEntry(It.IsAny<object>())).Returns(new Mock<Microsoft.Extensions.Caching.Memory.ICacheEntry>().Object);
cacheAndRetryBuilder.SetupGet(c => c.AppCache).Returns(cache.Object);
cacheAndRetryHandler = new(TestServices.RetryHandlersHelpers.GetCachingAsyncRetryPolicyMock(cacheAndRetryBuilder, c => c.DefaultRetryHttpResponseMessagePolicyBuilder()));
azureEnvironmentConfig = ExpensiveObjectTestUtility.AzureCloudConfig.AzureEnvironmentConfig!;
azureEnvironmentConfig = CommonUtilities.AzureCloud.AzureCloudConfig.ForUnitTesting().AzureEnvironmentConfig!;

terraSamApiClient = new TerraSamApiClient(TerraApiStubData.SamApiHost, tokenCredential.Object,
cacheAndRetryBuilder.Object, azureEnvironmentConfig, NullLogger<TerraSamApiClient>.Instance);
Expand Down
2 changes: 1 addition & 1 deletion src/Tes.ApiClients.Tests/TerraWsmApiClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void SetUp()
cache.Setup(c => c.CreateEntry(It.IsAny<object>())).Returns(new Mock<Microsoft.Extensions.Caching.Memory.ICacheEntry>().Object);
cacheAndRetryBuilder.SetupGet(c => c.AppCache).Returns(cache.Object);
cacheAndRetryHandler = new(TestServices.RetryHandlersHelpers.GetCachingAsyncRetryPolicyMock(cacheAndRetryBuilder, c => c.DefaultRetryHttpResponseMessagePolicyBuilder()));
azureEnvironmentConfig = AzureEnvironmentConfig.FromArmEnvironmentEndpoints(CommonUtilities.AzureCloud.AzureCloudConfig.FromKnownCloudNameAsync(CommonUtilities.AzureCloud.AzureCloudConfig.DefaultAzureCloudName).Result);
azureEnvironmentConfig = AzureEnvironmentConfig.FromArmEnvironmentEndpoints(CommonUtilities.AzureCloud.AzureCloudConfig.ForUnitTesting());

terraWsmApiClient = new TerraWsmApiClient(TerraApiStubData.WsmApiHost, tokenCredential.Object,
cacheAndRetryBuilder.Object, azureEnvironmentConfig, NullLogger<TerraWsmApiClient>.Instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void SetUp()
mockBlobServiceClient = new Mock<BlobServiceClient>();
RuntimeOptions options = new()
{
AzureEnvironmentConfig = AzureEnvironmentConfig.FromArmEnvironmentEndpoints(CommonUtilities.AzureCloud.AzureCloudConfig.FromKnownCloudNameAsync().Result)
AzureEnvironmentConfig = AzureEnvironmentConfig.FromArmEnvironmentEndpoints(CommonUtilities.AzureCloud.AzureCloudConfig.ForUnitTesting())
};

mockBlobApiHttpUtils = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void Initialize()

cachingRetryHandler = new CachingRetryPolicyBuilder(appCache, mockRetryOptions.Object);
pricingApiClient = new PriceApiClient(cachingRetryHandler, new NullLogger<PriceApiClient>());
var config = ExpensiveObjectTestUtility.AzureCloudConfig;
var config = CommonUtilities.AzureCloud.AzureCloudConfig.FromKnownCloudNameAsync().Result;
provider = new PriceApiBatchSkuInformationProvider(pricingApiClient, config, new NullLogger<PriceApiBatchSkuInformationProvider>());
//using var serviceProvider = new TestServices.TestServiceProvider<PriceApiBatchSkuInformationProvider>();
//var provider = serviceProvider.GetT();
Expand Down
2 changes: 1 addition & 1 deletion src/TesApi.Tests/Runner/TaskToNodeTaskConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void SetUp()
x.GetBlobUrlsAsync(It.IsAny<Uri>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult<IList<Uri>>([]));

var azureCloudIdentityConfig = AzureCloudConfig.FromKnownCloudNameAsync().Result.AzureEnvironmentConfig;
var azureCloudIdentityConfig = AzureCloudConfig.ForUnitTesting().AzureEnvironmentConfig;
taskToNodeTaskConverter = new TaskToNodeTaskConverter(Options.Create(terraOptions), Options.Create(storageOptions),
storageAccessProviderMock.Object, azureProxyMock.Object, azureCloudIdentityConfig, new NullLogger<TaskToNodeTaskConverter>());
}
Expand Down
2 changes: 1 addition & 1 deletion src/TesApi.Tests/StartupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void SetUp()
services.AddSingleton(hostEnv.Object);
#pragma warning restore CS0618

Startup.AzureCloudConfig = AzureCloudConfig.FromKnownCloudNameAsync().Result;
Startup.AzureCloudConfig = AzureCloudConfig.ForUnitTesting();
var configuration = builder.Build();
services.AddSingleton(configuration);
services.AddSingleton<IConfiguration>(configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void Setup()
};
azureProxyMock.Setup(p => p.GetStorageAccountKeyAsync(It.IsAny<StorageAccountInfo>(), It.IsAny<CancellationToken>())).ReturnsAsync(GenerateRandomTestAzureStorageKey());
azureProxyMock.Setup(p => p.GetStorageAccountInfoAsync(It.Is<string>(s => s.Equals(DefaultStorageAccountName)), It.IsAny<CancellationToken>())).ReturnsAsync(storageAccountInfo);
var config = ExpensiveObjectTestUtility.AzureCloudConfig.AzureEnvironmentConfig;
var config = CommonUtilities.AzureCloud.AzureCloudConfig.ForUnitTesting().AzureEnvironmentConfig;
defaultStorageAccessProvider = new DefaultStorageAccessProvider(NullLogger<DefaultStorageAccessProvider>.Instance, Options.Create(storageOptions), azureProxyMock.Object, config);
}

Expand Down
2 changes: 1 addition & 1 deletion src/TesApi.Tests/TerraStorageAccessProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void SetUp()
batchSchedulingOptions = new BatchSchedulingOptions() { Prefix = BatchSchedulingPrefix };
optionsMock.Setup(o => o.Value).Returns(terraOptions);
azureProxyMock = new Mock<IAzureProxy>();
var config = ExpensiveObjectTestUtility.AzureCloudConfig.AzureEnvironmentConfig;
var config = CommonUtilities.AzureCloud.AzureCloudConfig.ForUnitTesting().AzureEnvironmentConfig;
terraStorageAccessProvider = new TerraStorageAccessProvider(new(wsmApiClientMock.Object), azureProxyMock.Object, optionsMock.Object, Options.Create(batchSchedulingOptions), config, NullLogger<TerraStorageAccessProvider>.Instance);
}

Expand Down
2 changes: 1 addition & 1 deletion src/TesApi.Tests/TestServices/TestServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal TestServiceProvider(
Action<IServiceCollection> additionalActions = default)
{
Configuration = GetConfiguration(configuration);
var azureCloudConfig = ExpensiveObjectTestUtility.AzureCloudConfig;
var azureCloudConfig = CommonUtilities.AzureCloud.AzureCloudConfig.ForUnitTesting();
provider = new ServiceCollection()
.AddSingleton(_ => new TesServiceInfo { CreatedAt = DateTimeOffset.UtcNow, Environment = "unittest", Id = "unit-test-id", Organization = new() { Name = "unit-test-org", Url = "http://localhost/" }, Storage = [], UpdatedAt = DateTimeOffset.UtcNow })
.AddSingleton(azureCloudConfig)
Expand Down
2 changes: 1 addition & 1 deletion src/deploy-tes-on-azure.Tests/KubernetesManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class KubernetesManagerTests
[TestMethod]
public async Task ValuesTemplateSuccessfullyDeserializesTesdatabaseToYaml()
{
var manager = new KubernetesManager(new(), ExpensiveObjectTestUtility.AzureCloudConfig, (_, _, _) => throw new System.NotImplementedException(), System.Threading.CancellationToken.None);
var manager = new KubernetesManager(new(), CommonUtilities.AzureCloud.AzureCloudConfig.ForUnitTesting(), (_, _, _) => throw new System.NotImplementedException(), System.Threading.CancellationToken.None);
var helmValues = await manager.GetHelmValuesAsync(@"./cromwell-on-azure/helm/values-template.yaml");
Assert.IsNotNull(helmValues.TesDatabase);
}
Expand Down
Loading