Skip to content

Commit

Permalink
mgmt, improve live test (#22555)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored Jun 25, 2021
1 parent 9800d75 commit d15aa17
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.management.profile.AzureProfile;
import com.azure.core.test.annotation.DoNotRecord;
import com.azure.core.util.polling.LongRunningOperationStatus;
import com.azure.core.util.polling.PollResponse;
import com.azure.resourcemanager.compute.models.AvailabilitySet;
Expand Down Expand Up @@ -833,6 +834,7 @@ public void canRunScriptOnVM() {
}

@Test
@DoNotRecord(skipInPlayback = true)
public void canPerformSimulateEvictionOnSpotVirtualMachine() {
VirtualMachine virtualMachine = computeManager.virtualMachines()
.define(vmName)
Expand All @@ -843,7 +845,7 @@ public void canPerformSimulateEvictionOnSpotVirtualMachine() {
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("firstuser")
.withRootPassword(password())
.withSsh(sshPublicKey())
.withSpotPriority(VirtualMachineEvictionPolicyTypes.DEALLOCATE)
.withSize(VirtualMachineSizeTypes.fromString("Standard_D2a_v4"))
.create();
Expand All @@ -856,12 +858,23 @@ public void canPerformSimulateEvictionOnSpotVirtualMachine() {

// call simulate eviction
virtualMachine.simulateEviction();
ResourceManagerUtils.sleep(Duration.ofMinutes(30));
boolean deallocated = false;
int pollIntervalInMinutes = 5;
for (int i = 0; i < 30; i += pollIntervalInMinutes) {
ResourceManagerUtils.sleep(Duration.ofMinutes(pollIntervalInMinutes));

virtualMachine = computeManager.virtualMachines().getById(virtualMachine.id());
if (virtualMachine.powerState() == PowerState.DEALLOCATED) {
deallocated = true;
break;
}
}
Assertions.assertTrue(deallocated);

virtualMachine = computeManager.virtualMachines().getById(virtualMachine.id());
Assertions.assertNotNull(virtualMachine);
Assertions.assertNull(virtualMachine.osDiskStorageAccountType());
Assertions.assertTrue(virtualMachine.osDiskSize() == 0);
Assertions.assertEquals(0, virtualMachine.osDiskSize());
disk = computeManager.disks().getById(virtualMachine.osDiskId());
Assertions.assertEquals(DiskState.RESERVED, disk.innerModel().diskState());
}
Expand Down

0 comments on commit d15aa17

Please sign in to comment.