Skip to content

Commit

Permalink
Update SQL .NET SDK tests to get location from environment variable a…
Browse files Browse the repository at this point in the history
…nd fix TDE test (Azure#3535)

* Remove location hardcoding

* Re-do all test recordings

* Fix validation errors

* Remove .swp files

* Reorganize utilities

* Responded to PR comments
  • Loading branch information
nathannfan authored and shahabhijeet committed Aug 7, 2017
1 parent 638fb1a commit 7af6f44
Show file tree
Hide file tree
Showing 61 changed files with 25,223 additions and 10,242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void TestGetCapabilities()
{
SqlManagementClient sqlClient = context.GetClient<SqlManagementClient>();

LocationCapabilities capabilities = sqlClient.Capabilities.ListByLocation(SqlManagementTestUtilities.DefaultLocation);
LocationCapabilities capabilities = sqlClient.Capabilities.ListByLocation(TestEnvironmentUtilities.DefaultLocation);

Assert.NotNull(capabilities);

Expand Down
16 changes: 15 additions & 1 deletion src/SDKs/SqlManagement/Sql.Tests/DatabaseCrudScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
using Microsoft.Azure.Management.Sql;
using Microsoft.Azure.Management.Sql.Models;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.Azure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using Xunit;

Expand Down Expand Up @@ -348,7 +350,19 @@ public void TestDatabaseTransparentDataEncryptionConfiguration()

// Update TDE config
config.Status = TransparentDataEncryptionStatus.Disabled;
config = sqlClient.TransparentDataEncryptions.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, config);

// Sometimes the config is still being updated from the previous PUT, so execute with retry

SqlManagementTestUtilities.ExecuteWithRetry(() =>
{
config = sqlClient.TransparentDataEncryptions.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, config);
},
TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(5),
(CloudException e) =>
{
return e.Response.StatusCode == HttpStatusCode.Conflict;
});

Assert.Equal(TransparentDataEncryptionStatus.Disabled, config.Status);
}
}
Expand Down
29 changes: 11 additions & 18 deletions src/SDKs/SqlManagement/Sql.Tests/FailoverGroupCrudScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void TestCrudFailoverGroup()
// Create primary and partner servers
//
var sourceServer = context.CreateServer(resourceGroup);
var targetServer = context.CreateServer(resourceGroup, location: SqlManagementTestUtilities.DefaultSecondaryLocationId);
var targetServer = context.CreateServer(resourceGroup, location: TestEnvironmentUtilities.DefaultSecondaryLocationId);

// Create a failover group
//
Expand Down Expand Up @@ -124,24 +124,17 @@ public void TestCrudFailoverGroup()
var primaryDatabase = sqlClient.Databases.Get(resourceGroup.Name, sourceServer.Name, databaseName);

// A brief wait may be needed until the secondary database is fully created
Database secondaryDatabase;
DateTime startTime = DateTime.UtcNow;
TimeSpan retryTime = TimeSpan.FromMinutes(2);
TimeSpan retryDelay = HttpMockServer.Mode == HttpRecorderMode.Record ? TimeSpan.FromSeconds(5) : TimeSpan.Zero;
while (true)
Database secondaryDatabase = new Database();

SqlManagementTestUtilities.ExecuteWithRetry(() =>
{
try
{
secondaryDatabase = sqlClient.Databases.Get(resourceGroup.Name, targetServer.Name, databaseName);
break;
}
catch (CloudException e) when (
e.Response.StatusCode == HttpStatusCode.NotFound
&& DateTime.UtcNow < startTime + retryTime)
{
Thread.Sleep(retryDelay);
}
}
secondaryDatabase = sqlClient.Databases.Get(resourceGroup.Name, targetServer.Name, databaseName);
},
TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(5),
(CloudException e) =>
{
return e.Response.StatusCode == HttpStatusCode.NotFound;
});

Assert.NotNull(primaryDatabase.FailoverGroupId);
Assert.NotNull(secondaryDatabase.FailoverGroupId);
Expand Down
14 changes: 7 additions & 7 deletions src/SDKs/SqlManagement/Sql.Tests/ServerCrudScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public void TestCreateUpdateGetDropServer()
AdministratorLoginPassword = password,
Version = version12,
Tags = tags,
Location = SqlManagementTestUtilities.DefaultLocationId,
Location = TestEnvironmentUtilities.DefaultLocationId,
});
SqlManagementTestUtilities.ValidateServer(server1, serverNameV12, login, version12, tags, SqlManagementTestUtilities.DefaultLocationId);
SqlManagementTestUtilities.ValidateServer(server1, serverNameV12, login, version12, tags, TestEnvironmentUtilities.DefaultLocationId);

// Create second server
string server2 = SqlManagementTestUtilities.GenerateName();
Expand All @@ -48,17 +48,17 @@ public void TestCreateUpdateGetDropServer()
AdministratorLogin = login,
AdministratorLoginPassword = password,
Tags = tags,
Location = SqlManagementTestUtilities.DefaultLocationId,
Location = TestEnvironmentUtilities.DefaultLocationId,
});
SqlManagementTestUtilities.ValidateServer(v2Server, server2, login, version12, tags, SqlManagementTestUtilities.DefaultLocationId);
SqlManagementTestUtilities.ValidateServer(v2Server, server2, login, version12, tags, TestEnvironmentUtilities.DefaultLocationId);

// Get first server
var getServer1 = sqlClient.Servers.Get(resourceGroup.Name, serverNameV12);
SqlManagementTestUtilities.ValidateServer(getServer1, serverNameV12, login, version12, tags, SqlManagementTestUtilities.DefaultLocationId);
SqlManagementTestUtilities.ValidateServer(getServer1, serverNameV12, login, version12, tags, TestEnvironmentUtilities.DefaultLocationId);

// Get second server
var getServer2 = sqlClient.Servers.Get(resourceGroup.Name, server2);
SqlManagementTestUtilities.ValidateServer(getServer2, server2, login, version12, tags, SqlManagementTestUtilities.DefaultLocationId);
SqlManagementTestUtilities.ValidateServer(getServer2, server2, login, version12, tags, TestEnvironmentUtilities.DefaultLocationId);

var listServers = sqlClient.Servers.ListByResourceGroup(resourceGroup.Name);
Assert.Equal(2, listServers.Count());
Expand All @@ -69,7 +69,7 @@ public void TestCreateUpdateGetDropServer()
{ "asdf", "zxcv" }
};
var updateServer1 = sqlClient.Servers.Update(resourceGroup.Name, serverNameV12, new ServerUpdate { Tags = newTags });
SqlManagementTestUtilities.ValidateServer(updateServer1, serverNameV12, login, version12, newTags, SqlManagementTestUtilities.DefaultLocationId);
SqlManagementTestUtilities.ValidateServer(updateServer1, serverNameV12, login, version12, newTags, TestEnvironmentUtilities.DefaultLocationId);

// Drop server, update count
sqlClient.Servers.Delete(resourceGroup.Name, serverNameV12);
Expand Down
Loading

0 comments on commit 7af6f44

Please sign in to comment.