fix case BatchCreateVmWhenSetReservedMemoryCase
package org.zstack.test.integration.kvm.globalconfig
+import org.zstack.core.db.Q
+import org.zstack.header.vm.VmInstanceState
+import org.zstack.header.vm.VmInstanceVO
+import org.zstack.header.vm.VmInstanceVO_
import org.zstack.network.securitygroup.SecurityGroupConstant
import org.zstack.sdk.CreateVmInstanceAction
import org.zstack.sdk.GetCpuMemoryCapacityAction
@@ -12,6 +16,7 @@ import org.zstack.utils.data.SizeUnit
*/
class BatchCreateVmWhenSetReservedMemoryCase extends SubCase {
EnvSpec env
+ int correctCount = 9
@Override
void clean() {
@@ -121,7 +126,7 @@ class BatchCreateVmWhenSetReservedMemoryCase extends SubCase {
def _1CPU1G = (env.specByName("instanceOffering") as InstanceOfferingSpec).inventory.uuid
def l3uuid = (env.specByName("pubL3") as L3NetworkSpec).inventory.uuid
- for(int i=0;i++;i<num){
+ for (int i = 0; i < num; i++) {
createVmInstance {
def vmName = "VM"+i
name = vmName
@@ -130,6 +135,7 @@ class BatchCreateVmWhenSetReservedMemoryCase extends SubCase {
l3NetworkUuids = [l3uuid]
}
}
+ assert correctCount == Q.New(VmInstanceVO.class).select(VmInstanceVO_.uuid).eq(VmInstanceVO_.state, VmInstanceState.Running).listValues().size()
expect(AssertionError.class) {
createVmInstance {
name = "VMM"
@@ -138,6 +144,14 @@ class BatchCreateVmWhenSetReservedMemoryCase extends SubCase {
l3NetworkUuids = [l3uuid]
}
}
+ List<String> vmUuids = Q.New(VmInstanceVO.class).select(VmInstanceVO_.uuid).eq(VmInstanceVO_.state, VmInstanceState.Running).listValues()
+ assert vmUuids.size() == correctCount
+ //free resource
+ for (String vmUuid : vmUuids) {
+ destroyVmInstance {
+ uuid = vmUuid
+ }
+ }
}
void testConcurrentCreateVMs(Long num) {
@@ -156,12 +170,13 @@ class BatchCreateVmWhenSetReservedMemoryCase extends SubCase {
l3NetworkUuids = [l3uuid]
}
}
-
threads.add(thread)
})
threads.each { it.join() }
+ assert correctCount == Q.New(VmInstanceVO.class).select(VmInstanceVO_.uuid).eq(VmInstanceVO_.state, VmInstanceState.Running).listValues().size()
+
GetCpuMemoryCapacityAction getCpuMemoryCapacityAction = new GetCpuMemoryCapacityAction()
getCpuMemoryCapacityAction.all = true
getCpuMemoryCapacityAction.sessionId = adminSession()
