Skip to content

Commit f5a1824

Browse files
author
jasper-schneider
committed
Re-record Batch scenario tests with new API version
Some small changes to improve test robustness.
1 parent 2c25a0e commit f5a1824

File tree

112 files changed

+61445
-24069
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+61445
-24069
lines changed

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/BatchAccountTests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ function Test-GetBatchAccountsUnderResourceGroups
142142
$account12 = Get-BatchAccountName
143143
$account21 = Get-BatchAccountName
144144
$location1 = Get-BatchAccountProviderLocation
145-
$location2 = Get-BatchAccountProviderLocation 1
146-
$location3 = Get-BatchAccountProviderLocation 2
145+
$location2 = Get-BatchAccountProviderLocation 4
146+
$location3 = Get-BatchAccountProviderLocation 7
147147

148148
try
149149
{
@@ -183,7 +183,7 @@ function Test-CreateAndRemoveBatchAccountViaPiping
183183
$account2 = Get-BatchAccountName
184184
$resourceGroup = Get-ResourceGroupName
185185
$location1 = Get-BatchAccountProviderLocation
186-
$location2 = Get-BatchAccountProviderLocation 1
186+
$location2 = Get-BatchAccountProviderLocation 4
187187

188188
try
189189
{

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/JobTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ public void TestGetJobById()
6363
public void TestListJobsByFilter()
6464
{
6565
BatchController controller = BatchController.NewInstance;
66-
string jobId1 = "testId1";
67-
string jobId2 = "testId2";
66+
string jobId1 = "filterTestId1";
67+
string jobId2 = "filterTestId2";
6868
string jobId3 = "thirdtestId";
69-
string state = "active";
69+
string prefix = "filterTest";
7070
int matches = 2;
7171
BatchAccountContext context = null;
7272
controller.RunPsTestWorkflow(
73-
() => { return new string[] { string.Format("Test-ListJobsByFilter '{0}' '{1}' '{2}'", accountName, state.ToString(), matches) }; },
73+
() => { return new string[] { string.Format("Test-ListJobsByFilter '{0}' '{1}' '{2}'", accountName, prefix, matches) }; },
7474
() =>
7575
{
7676
context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, accountName);

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/JobTests.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,17 @@ Tests querying for Batch jobs using a filter
252252
#>
253253
function Test-ListJobsByFilter
254254
{
255-
param([string]$accountName, [string]$state, [string]$matches)
255+
param([string]$accountName, [string]$prefix, [string]$matches)
256256

257257
$context = Get-AzureRmBatchAccountKeys -Name $accountName
258-
$filter = "state eq'" + "$state" + "'"
258+
$filter = "startswith(id,'$prefix')"
259259

260260
$jobs = Get-AzureBatchJob_ST -Filter $filter -BatchContext $context
261261

262262
Assert-AreEqual $matches $jobs.Length
263263
foreach($job in $jobs)
264264
{
265-
Assert-True { $job.Id.StartsWith("$idPrefix") }
265+
Assert-True { $job.Id.StartsWith("$prefix") }
266266
}
267267
}
268268

@@ -441,8 +441,8 @@ function Test-DeleteJob
441441
$context = Get-AzureRmBatchAccountKeys -Name $accountName
442442

443443
# Verify the job exists
444-
$jobs = Get-AzureBatchJob_ST -BatchContext $context
445-
Assert-AreEqual 1 $jobs.Count
444+
$job = Get-AzureBatchJob_ST $jobId -BatchContext $context
445+
Assert-AreNotEqual $null $job
446446

447447
if ($usePipeline -eq '1')
448448
{
@@ -454,7 +454,7 @@ function Test-DeleteJob
454454
}
455455

456456
# Verify the job was deleted
457-
$jobs = Get-AzureBatchJob_ST -BatchContext $context
457+
$jobs = Get-AzureBatchJob_ST -Filter "id eq '$jobId'" -BatchContext $context
458458
Assert-True { $jobs -eq $null -or $jobs[0].State.ToString().ToLower() -eq 'deleting' }
459459
}
460460

@@ -476,7 +476,7 @@ function Test-DisableAndEnableJob
476476

477477
# Verify the job was Disabled
478478
$job = Get-AzureBatchJob_ST $jobId -BatchContext $context
479-
Assert-AreEqual 'Disabled' $job.State
479+
Assert-True { ($job.State.ToString().ToLower() -eq 'disabled') -or ($job.State.ToString().ToLower() -eq 'disabling') }
480480

481481
Enable-AzureBatchJob_ST $jobId -BatchContext $context
482482

@@ -487,7 +487,7 @@ function Test-DisableAndEnableJob
487487
# Verify using the pipeline
488488
$job | Disable-AzureBatchJob_ST -DisableJobOption Terminate -BatchContext $context
489489
$job = Get-AzureBatchJob_ST $jobId -BatchContext $context
490-
Assert-AreEqual 'Disabled' $job.State
490+
Assert-True { ($job.State.ToString().ToLower() -eq 'disabled') -or ($job.State.ToString().ToLower() -eq 'disabling') }
491491

492492
$job | Enable-AzureBatchJob_ST -BatchContext $context
493493
$job = Get-AzureBatchJob_ST -Filter "id eq '$jobId'" -BatchContext $context

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/PoolTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public class PoolTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
2828
private const string commonAccountName = ScenarioTestHelpers.SharedAccount;
2929
private const string testPoolId = ScenarioTestHelpers.SharedPool;
3030

31+
// Get from WATaskOSFamilyVersions table, which lags behind https://azure.microsoft.com/en-us/documentation/articles/cloud-services-guestos-update-matrix/
32+
private const string specificOSVersion = "WA-GUEST-OS-4.22_201507-01";
33+
3134
[Fact]
3235
[Trait(Category.AcceptanceType, Category.CheckIn)]
3336
public void TestNewPool()
@@ -443,7 +446,7 @@ private void TestChangeOSVersion(bool usePipeline)
443446
{
444447
context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, commonAccountName);
445448
string currentTargetOSVersion = ScenarioTestHelpers.WaitForOSVersionChange(controller, context, testPoolId);
446-
newTargetOSVersion = currentTargetOSVersion == "*" ? "WA-GUEST-OS-4.20_201505-01" : "*";
449+
newTargetOSVersion = currentTargetOSVersion == "*" ? specificOSVersion : "*";
447450
},
448451
null,
449452
TestUtilities.GetCallingClass(),

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/ScenarioTestHelpers.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,43 @@ public static string AddTestCertificate(BatchController controller, BatchAccount
9393
BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient);
9494

9595
X509Certificate2 cert = new X509Certificate2(filePath);
96+
ListCertificateOptions getParameters = new ListCertificateOptions(context, behaviors)
97+
{
98+
ThumbprintAlgorithm = BatchTestHelpers.TestCertificateAlgorithm,
99+
Thumbprint = cert.Thumbprint,
100+
Select = "thumbprint,state"
101+
};
102+
103+
try
104+
{
105+
PSCertificate existingCert = client.ListCertificates(getParameters).FirstOrDefault();
106+
DateTime start = DateTime.Now;
107+
DateTime end = start.AddMinutes(5);
108+
109+
// Cert might still be deleting from other tests, so we wait for the delete to finish.
110+
while (existingCert != null && existingCert.State == CertificateState.Deleting)
111+
{
112+
if (DateTime.Now > end)
113+
{
114+
throw new TimeoutException("Timed out waiting for existing cert to be deleted.");
115+
}
116+
Sleep(5000);
117+
existingCert = client.ListCertificates(getParameters).FirstOrDefault();
118+
}
119+
}
120+
catch (AggregateException ex)
121+
{
122+
foreach (Exception inner in ex.InnerExceptions)
123+
{
124+
BatchException batchEx = inner as BatchException;
125+
// When the cert doesn't exist, we get a 404 error. For all other errors, throw.
126+
if (batchEx == null || !batchEx.Message.Contains("CertificateNotFound"))
127+
{
128+
throw;
129+
}
130+
}
131+
}
132+
96133
NewCertificateParameters parameters = new NewCertificateParameters(context, null, cert.RawData, behaviors);
97134

98135
client.AddCertificate(parameters);

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/TaskTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,9 @@ public void TestTerminateTask()
301301
{
302302
context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, accountName);
303303
ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
304-
ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId1);
305-
ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId2);
304+
// Make the tasks long running so they can be terminated before they finish execution
305+
ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId1, "ping -t localhost -w 60");
306+
ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId2, "ping -t localhost -w 60");
306307
},
307308
() =>
308309
{

src/ResourceManager/AzureBatch/Commands.Batch.Test/SessionRecords/Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests/TestBatchAccountKeys.json

Lines changed: 355 additions & 277 deletions
Large diffs are not rendered by default.

src/ResourceManager/AzureBatch/Commands.Batch.Test/SessionRecords/Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests/TestCreateAndRemoveBatchAccountViaPiping.json

Lines changed: 349 additions & 324 deletions
Large diffs are not rendered by default.

src/ResourceManager/AzureBatch/Commands.Batch.Test/SessionRecords/Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests/TestCreateExistingBatchAccount.json

Lines changed: 286 additions & 154 deletions
Large diffs are not rendered by default.

src/ResourceManager/AzureBatch/Commands.Batch.Test/SessionRecords/Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests/TestGetBatchAccountsUnderResourceGroups.json

Lines changed: 703 additions & 378 deletions
Large diffs are not rendered by default.

src/ResourceManager/AzureBatch/Commands.Batch.Test/SessionRecords/Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests/TestGetNonExistingBatchAccount.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
"no-cache"
2626
],
2727
"x-ms-ratelimit-remaining-subscription-reads": [
28-
"14951"
28+
"14996"
2929
],
3030
"x-ms-request-id": [
31-
"48f50f6a-d361-43c9-b451-d9494b8ed4ea"
31+
"7e87fd7c-acf1-460f-a797-152e92f93c32"
3232
],
3333
"x-ms-correlation-request-id": [
34-
"48f50f6a-d361-43c9-b451-d9494b8ed4ea"
34+
"7e87fd7c-acf1-460f-a797-152e92f93c32"
3535
],
3636
"x-ms-routing-request-id": [
37-
"WESTUS:20150709T190213Z:48f50f6a-d361-43c9-b451-d9494b8ed4ea"
37+
"WESTUS:20151026T231649Z:7e87fd7c-acf1-460f-a797-152e92f93c32"
3838
],
3939
"Strict-Transport-Security": [
4040
"max-age=31536000; includeSubDomains"
@@ -43,7 +43,7 @@
4343
"no-cache"
4444
],
4545
"Date": [
46-
"Thu, 09 Jul 2015 19:02:12 GMT"
46+
"Mon, 26 Oct 2015 23:16:48 GMT"
4747
]
4848
},
4949
"StatusCode": 200

src/ResourceManager/AzureBatch/Commands.Batch.Test/SessionRecords/Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests/TestUpdatesExistingBatchAccount.json

Lines changed: 314 additions & 188 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)