public void Bug1996130_JobTaskVerbsFailAfterDoubleRefresh() { void test() { using BatchClient batchCli = TestUtilities.OpenBatchClient(TestUtilities.GetCredentialsFromEnvironment()); string jobId = "Bug1996130Job-" + TestUtilities.GetMyName(); try { // get a job/task to test. use workflow CloudJob boundJob = null; { // need a bound job/task for the tests so set one up CloudJob tsh = batchCli.JobOperations.CreateJob(jobId, new PoolInformation()); tsh.PoolInformation.PoolId = poolFixture.PoolId; tsh.Commit(); boundJob = batchCli.JobOperations.GetJob(jobId); boundJob.AddTask(new CloudTask("Bug1996130_task", "cmd /c hostname")); } // test task double refresh { // get the task CloudTask boundTask = batchCli.JobOperations.ListTasks(jobId).First(); // double refresh boundTask.Refresh(); boundTask.Refresh(); // this branch of the bug actually fixed in the other doublerefesh checkin by matthchr // do verbs boundTask.Refresh(); boundTask.Delete(); Thread.Sleep(5000); // give server time to do its deed List <CloudTask> tasks = batchCli.JobOperations.ListTasks(jobId).ToList(); // confirm delete suceeded Assert.Empty(tasks); } // test job double refresh and verbs { boundJob = batchCli.JobOperations.GetJob(jobId); // double refresh to taint the instance... lost path variable boundJob.Refresh(); boundJob.Refresh(); // this used to fail/throw boundJob.Refresh(); // this should fail but does not boundJob.Delete(); // yet another verb that suceeds CloudJob job = batchCli.JobOperations.ListJobs().ToList().FirstOrDefault(j => j.Id == jobId); // confirm job delete suceeded Assert.True(job == null || (JobState.Deleting == job.State)); } } finally { TestUtilities.DeleteJobIfExistsAsync(batchCli, jobId).Wait(); } } SynchronizationContextHelper.RunTest(test, TestTimeout); }