PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://gitlab.com/jslee1/azure-powershell
C# | 380 lines | 346 code | 19 blank | 15 comment | 0 complexity | b730982269d82718a664cd9da236fafc MD5 | raw file
  1. // ----------------------------------------------------------------------------------
  2. //
  3. // Copyright Microsoft Corporation
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. // ----------------------------------------------------------------------------------
  14. using Microsoft.Azure.Test;
  15. using Microsoft.WindowsAzure.Commands.ScenarioTest;
  16. using Xunit;
  17. namespace Microsoft.Azure.Commands.Batch.Test.ScenarioTests
  18. {
  19. public class TaskTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
  20. {
  21. public TaskTests(Xunit.Abstractions.ITestOutputHelper output)
  22. {
  23. ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
  24. }
  25. [Fact]
  26. [Trait(Category.AcceptanceType, Category.CheckIn)]
  27. public void TestCreateTask()
  28. {
  29. BatchController controller = BatchController.NewInstance;
  30. string jobId = "createTaskJob";
  31. BatchAccountContext context = null;
  32. controller.RunPsTestWorkflow(
  33. () => { return new string[] { string.Format("Test-CreateTask '{0}'", jobId) }; },
  34. () =>
  35. {
  36. context = new ScenarioTestContext();
  37. ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
  38. },
  39. () =>
  40. {
  41. ScenarioTestHelpers.DeleteJob(controller, context, jobId);
  42. },
  43. TestUtilities.GetCallingClass(),
  44. TestUtilities.GetCurrentMethodName());
  45. }
  46. [Fact]
  47. [Trait(Category.AcceptanceType, Category.CheckIn)]
  48. public void TestCreateTaskCollection()
  49. {
  50. BatchController controller = BatchController.NewInstance;
  51. string jobId = "createTaskCollectionJob";
  52. BatchAccountContext context = null;
  53. controller.RunPsTestWorkflow(
  54. () => { return new string[] { string.Format("Test-CreateTaskCollection '{0}'", jobId) }; },
  55. () =>
  56. {
  57. context = new ScenarioTestContext();
  58. ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
  59. },
  60. () =>
  61. {
  62. ScenarioTestHelpers.DeleteJob(controller, context, jobId);
  63. },
  64. TestUtilities.GetCallingClass(),
  65. TestUtilities.GetCurrentMethodName());
  66. }
  67. [Fact]
  68. public void TestGetTaskById()
  69. {
  70. BatchController controller = BatchController.NewInstance;
  71. string jobId = "getTaskJob";
  72. string taskId = "testTask";
  73. BatchAccountContext context = null;
  74. controller.RunPsTestWorkflow(
  75. () => { return new string[] { string.Format("Test-GetTaskById '{0}' '{1}'", jobId, taskId) }; },
  76. () =>
  77. {
  78. context = new ScenarioTestContext();
  79. ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
  80. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId);
  81. },
  82. () =>
  83. {
  84. ScenarioTestHelpers.DeleteJob(controller, context, jobId);
  85. },
  86. TestUtilities.GetCallingClass(),
  87. TestUtilities.GetCurrentMethodName());
  88. }
  89. [Fact]
  90. public void TestListTasksByFilter()
  91. {
  92. BatchController controller = BatchController.NewInstance;
  93. string jobId = "filterTaskJob";
  94. string taskId1 = "testTask1";
  95. string taskId2 = "testTask2";
  96. string taskId3 = "thirdTestTask";
  97. string taskPrefix = "testTask";
  98. int matches = 2;
  99. BatchAccountContext context = null;
  100. controller.RunPsTestWorkflow(
  101. () => { return new string[] { string.Format("Test-ListTasksByFilter '{0}' '{1}' '{2}'", jobId, taskPrefix, matches) }; },
  102. () =>
  103. {
  104. context = new ScenarioTestContext();
  105. ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
  106. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId1);
  107. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId2);
  108. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId3);
  109. },
  110. () =>
  111. {
  112. ScenarioTestHelpers.DeleteJob(controller, context, jobId);
  113. },
  114. TestUtilities.GetCallingClass(),
  115. TestUtilities.GetCurrentMethodName());
  116. }
  117. [Fact]
  118. [Trait(Category.AcceptanceType, Category.CheckIn)]
  119. public void TestGetAndListTasksWithSelect()
  120. {
  121. BatchController controller = BatchController.NewInstance;
  122. BatchAccountContext context = null;
  123. string jobId = "selectTaskTest";
  124. string taskId = "testTask1";
  125. controller.RunPsTestWorkflow(
  126. () => { return new string[] { string.Format("Test-GetAndListTasksWithSelect '{0}' '{1}'", jobId, taskId) }; },
  127. () =>
  128. {
  129. context = new ScenarioTestContext();
  130. ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
  131. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId);
  132. },
  133. () =>
  134. {
  135. ScenarioTestHelpers.DeleteJob(controller, context, jobId);
  136. },
  137. TestUtilities.GetCallingClass(),
  138. TestUtilities.GetCurrentMethodName());
  139. }
  140. [Fact]
  141. public void TestListTasksWithMaxCount()
  142. {
  143. BatchController controller = BatchController.NewInstance;
  144. string jobId = "maxCountTaskJob";
  145. string taskId1 = "testTask1";
  146. string taskId2 = "testTask2";
  147. string taskId3 = "testTask3";
  148. int maxCount = 1;
  149. BatchAccountContext context = null;
  150. controller.RunPsTestWorkflow(
  151. () => { return new string[] { string.Format("Test-ListTasksWithMaxCount '{0}' '{1}'", jobId, maxCount) }; },
  152. () =>
  153. {
  154. context = new ScenarioTestContext();
  155. ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
  156. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId1);
  157. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId2);
  158. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId3);
  159. },
  160. () =>
  161. {
  162. ScenarioTestHelpers.DeleteJob(controller, context, jobId);
  163. },
  164. TestUtilities.GetCallingClass(),
  165. TestUtilities.GetCurrentMethodName());
  166. }
  167. [Fact]
  168. public void TestListAllTasks()
  169. {
  170. BatchController controller = BatchController.NewInstance;
  171. string jobId = "listTaskJob";
  172. string taskId1 = "testTask1";
  173. string taskId2 = "testTask2";
  174. string taskId3 = "testTask3";
  175. int count = 3;
  176. BatchAccountContext context = null;
  177. controller.RunPsTestWorkflow(
  178. () => { return new string[] { string.Format("Test-ListAllTasks '{0}' '{1}'", jobId, count) }; },
  179. () =>
  180. {
  181. context = new ScenarioTestContext();
  182. ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
  183. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId1);
  184. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId2);
  185. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId3);
  186. },
  187. () =>
  188. {
  189. ScenarioTestHelpers.DeleteJob(controller, context, jobId);
  190. },
  191. TestUtilities.GetCallingClass(),
  192. TestUtilities.GetCurrentMethodName());
  193. }
  194. [Fact]
  195. public void TestListTaskPipeline()
  196. {
  197. BatchController controller = BatchController.NewInstance;
  198. string jobId = "listTaskPipeJob";
  199. string taskId = "testTask";
  200. BatchAccountContext context = null;
  201. controller.RunPsTestWorkflow(
  202. () => { return new string[] { string.Format("Test-ListTaskPipeline '{0}' '{1}'", jobId, taskId) }; },
  203. () =>
  204. {
  205. context = new ScenarioTestContext();
  206. ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
  207. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId);
  208. },
  209. () =>
  210. {
  211. ScenarioTestHelpers.DeleteJob(controller, context, jobId);
  212. },
  213. TestUtilities.GetCallingClass(),
  214. TestUtilities.GetCurrentMethodName());
  215. }
  216. [Fact]
  217. public void TestUpdateTask()
  218. {
  219. BatchController controller = BatchController.NewInstance;
  220. string jobId = "updateTaskJob";
  221. string taskId = "testTask";
  222. BatchAccountContext context = null;
  223. controller.RunPsTestWorkflow(
  224. () => { return new string[] { string.Format("Test-UpdateTask '{0}' '{1}'", jobId, taskId) }; },
  225. () =>
  226. {
  227. context = new ScenarioTestContext();
  228. ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
  229. // Make the task long running so the constraints can be updated
  230. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId, "ping -t localhost -w 60");
  231. },
  232. () =>
  233. {
  234. ScenarioTestHelpers.DeleteJob(controller, context, jobId);
  235. },
  236. TestUtilities.GetCallingClass(),
  237. TestUtilities.GetCurrentMethodName());
  238. }
  239. [Fact]
  240. [Trait(Category.AcceptanceType, Category.CheckIn)]
  241. public void TestDeleteTask()
  242. {
  243. BatchController controller = BatchController.NewInstance;
  244. string jobId = "deleteTaskJob";
  245. string taskId = "testTask";
  246. BatchAccountContext context = null;
  247. controller.RunPsTestWorkflow(
  248. () => { return new string[] { string.Format("Test-DeleteTask '{0}' '{1}' '0'", jobId, taskId) }; },
  249. () =>
  250. {
  251. context = new ScenarioTestContext();
  252. ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
  253. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId);
  254. },
  255. () =>
  256. {
  257. ScenarioTestHelpers.DeleteJob(controller, context, jobId);
  258. },
  259. TestUtilities.GetCallingClass(),
  260. TestUtilities.GetCurrentMethodName());
  261. }
  262. [Fact]
  263. public void TestDeleteTaskPipeline()
  264. {
  265. BatchController controller = BatchController.NewInstance;
  266. string jobId = "deleteTaskPipeJob";
  267. string taskId = "testTask";
  268. BatchAccountContext context = null;
  269. controller.RunPsTestWorkflow(
  270. () => { return new string[] { string.Format("Test-DeleteTask '{0}' '{1}' '1'", jobId, taskId) }; },
  271. () =>
  272. {
  273. context = new ScenarioTestContext();
  274. ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
  275. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId);
  276. },
  277. () =>
  278. {
  279. ScenarioTestHelpers.DeleteJob(controller, context, jobId);
  280. },
  281. TestUtilities.GetCallingClass(),
  282. TestUtilities.GetCurrentMethodName());
  283. }
  284. [Fact]
  285. public void TestTerminateTask()
  286. {
  287. BatchController controller = BatchController.NewInstance;
  288. BatchAccountContext context = null;
  289. string jobId = "testTerminateTaskJob";
  290. string taskId1 = "testTask1";
  291. string taskId2 = "testTask2";
  292. controller.RunPsTestWorkflow(
  293. () => { return new string[] { string.Format("Test-TerminateTask '{0}' '{1}' '{2}'", jobId, taskId1, taskId2) }; },
  294. () =>
  295. {
  296. context = new ScenarioTestContext();
  297. ScenarioTestHelpers.CreateTestJob(controller, context, jobId);
  298. // Make the tasks long running so they can be terminated before they finish execution
  299. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId1, "ping -t localhost -w 60");
  300. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId2, "ping -t localhost -w 60");
  301. },
  302. () =>
  303. {
  304. ScenarioTestHelpers.DeleteJob(controller, context, jobId);
  305. },
  306. TestUtilities.GetCallingClass(),
  307. TestUtilities.GetCurrentMethodName());
  308. }
  309. [Fact]
  310. public void TestListSubtasksWithMaxCount()
  311. {
  312. BatchController controller = BatchController.NewInstance;
  313. string jobId = "maxCountSubtaskJob";
  314. string taskId = "testTask";
  315. int numInstances = 3;
  316. int maxCount = 1;
  317. BatchAccountContext context = null;
  318. controller.RunPsTestWorkflow(
  319. () => { return new string[] { string.Format("Test-ListSubtasksWithMaxCount '{0}' '{1}' '{2}'", jobId, taskId, maxCount) }; },
  320. () =>
  321. {
  322. context = new ScenarioTestContext();
  323. ScenarioTestHelpers.CreateMpiPoolIfNotExists(controller, context);
  324. ScenarioTestHelpers.CreateTestJob(controller, context, jobId, ScenarioTestHelpers.MpiPoolId);
  325. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId, "cmd /c hostname", numInstances);
  326. ScenarioTestHelpers.WaitForTaskCompletion(controller, context, jobId, taskId);
  327. },
  328. () =>
  329. {
  330. ScenarioTestHelpers.DeleteJob(controller, context, jobId);
  331. },
  332. TestUtilities.GetCallingClass(),
  333. TestUtilities.GetCurrentMethodName());
  334. }
  335. [Fact]
  336. public void TestListAllSubtasks()
  337. {
  338. BatchController controller = BatchController.NewInstance;
  339. string jobId = "listSubtaskJob";
  340. string taskId = "testTask";
  341. int numInstances = 3;
  342. BatchAccountContext context = null;
  343. controller.RunPsTestWorkflow(
  344. () => { return new string[] { string.Format("Test-ListAllSubtasks '{0}' '{1}' '{2}'", jobId, taskId, numInstances) }; },
  345. () =>
  346. {
  347. context = new ScenarioTestContext();
  348. ScenarioTestHelpers.CreateMpiPoolIfNotExists(controller, context);
  349. ScenarioTestHelpers.CreateTestJob(controller, context, jobId, ScenarioTestHelpers.MpiPoolId);
  350. ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId, "cmd /c hostname", numInstances);
  351. ScenarioTestHelpers.WaitForTaskCompletion(controller, context, jobId, taskId);
  352. },
  353. () =>
  354. {
  355. ScenarioTestHelpers.DeleteJob(controller, context, jobId);
  356. },
  357. TestUtilities.GetCallingClass(),
  358. TestUtilities.GetCurrentMethodName());
  359. }
  360. }
  361. }