Repository: vmware/govmomi
Pull request #2353 (2021-04-08 23:26:41)

export simulator.task.Wait
Handy to have for external code that works with simulator.Task


Patch:
diff --git a/simulator/folder.go b/simulator/folder.go
index a0a4ecc7..20ad65e6 100644
--- a/simulator/folder.go
+++ b/simulator/folder.go
@@ -266,7 +266,7 @@ func (p *StoragePod) MoveIntoFolderTask(ctx *Context, c *types.MoveIntoFolder_Ta
 		f := &Folder{Folder: p.Folder}
 		id := f.MoveIntoFolderTask(ctx, c).(*methods.MoveIntoFolder_TaskBody).Res.Returnval
 		ftask := Map.Get(id).(*Task)
-		ftask.wait()
+		ftask.Wait()
 		if ftask.Info.Error != nil {
 			return nil, ftask.Info.Error.Fault
 		}
@@ -688,7 +688,7 @@ func (f *Folder) DestroyTask(ctx *Context, req *types.Destroy_Task) soap.HasFaul
 				}).(*methods.Destroy_TaskBody).Res.Returnval
 
 				t := Map.Get(id).(*Task)
-				t.wait()
+				t.Wait()
 				if t.Info.Error != nil {
 					fault = t.Info.Error.Fault // For example, can't destroy a powered on VM
 				}
diff --git a/simulator/resource_pool.go b/simulator/resource_pool.go
index 05840619..7df6e577 100644
--- a/simulator/resource_pool.go
+++ b/simulator/resource_pool.go
@@ -225,7 +225,7 @@ func (p *ResourcePool) ImportVApp(ctx *Context, req *types.ImportVApp) soap.HasF
 	})
 
 	ctask := Map.Get(res.(*methods.CreateVM_TaskBody).Res.Returnval).(*Task)
-	ctask.wait()
+	ctask.Wait()
 
 	if ctask.Info.Error != nil {
 		body.Fault_ = Fault("", ctask.Info.Error.Fault)
@@ -406,7 +406,7 @@ func (a *VirtualApp) CloneVAppTask(ctx *Context, req *types.CloneVApp_Task) soap
 			})
 
 			ctask := Map.Get(res.(*methods.CloneVM_TaskBody).Res.Returnval).(*Task)
-			ctask.wait()
+			ctask.Wait()
 			if ctask.Info.Error != nil {
 				return nil, ctask.Info.Error.Fault
 			}
diff --git a/simulator/task.go b/simulator/task.go
index fa969f8c..fb206892 100644
--- a/simulator/task.go
+++ b/simulator/task.go
@@ -138,10 +138,11 @@ func (t *Task) Run(ctx *Context) types.ManagedObjectReference {
 // It polls for task completion to avoid the need to set up a PropertyCollector.
 func (t *Task) RunBlocking(ctx *Context) {
 	_ = t.Run(ctx)
-	t.wait()
+	t.Wait()
 }
 
-func (t *Task) wait() {
+// Wait blocks until the task is complete.
+func (t *Task) Wait() {
 	// we do NOT want to share our lock with the tasks's context, because
 	// the goroutine that executes the task will use ctx to update the
 	// state (among other things).
diff --git a/simulator/virtual_machine.go b/simulator/virtual_machine.go
index 4bd639f2..4403426b 100644
--- a/simulator/virtual_machine.go
+++ b/simulator/virtual_machine.go
@@ -1251,7 +1251,7 @@ func (vm *VirtualMachine) removeDevice(ctx *Context, devices object.VirtualDevic
 						Datacenter: &dc.Self,
 					})
 					ctask := Map.Get(res.(*methods.DeleteVirtualDisk_TaskBody).Res.Returnval).(*Task)
-					ctask.wait()
+					ctask.Wait()
 				}
 			}
 			Map.Update(vm, []types.PropertyChange{
@@ -1511,14 +1511,14 @@ func (vm *VirtualMachine) ResetVMTask(ctx *Context, req *types.ResetVM_Task) soa
 	task := CreateTask(vm, "reset", func(task *Task) (types.AnyType, types.BaseMethodFault) {
 		res := vm.PowerOffVMTask(ctx, &types.PowerOffVM_Task{This: vm.Self})
 		ctask := Map.Get(res.(*methods.PowerOffVM_TaskBody).Res.Returnval).(*Task)
-		ctask.wait()
+		ctask.Wait()
 		if ctask.Info.Error != nil {
 			return nil, ctask.Info.Error.Fault
 		}
 
 		res = vm.PowerOnVMTask(ctx, &types.PowerOnVM_Task{This: vm.Self})
 		ctask = Map.Get(res.(*methods.PowerOnVM_TaskBody).Res.Returnval).(*Task)
-		ctask.wait()
+		ctask.Wait()
 
 		return nil, nil
 	})
@@ -1773,7 +1773,7 @@ func (vm *VirtualMachine) CloneVMTask(ctx *Context, req *types.CloneVM_Task) soa
 			return nil, ctask.Info.Error.Fault
 		}
 
-		ctask.wait()
+		ctask.Wait()
 
 		ref := ctask.Info.Result.(types.ManagedObjectReference)
 		clone := Map.Get(ref).(*VirtualMachine)


Test patch:
diff --git a/simulator/entity_test.go b/simulator/entity_test.go
index 2fb75332..e708b57c 100644
--- a/simulator/entity_test.go
+++ b/simulator/entity_test.go
@@ -60,7 +60,7 @@ func TestRename(t *testing.T) {
 		}).(*methods.Rename_TaskBody).Res.Returnval
 
 		task := Map.Get(id).(*Task)
-		task.wait()
+		task.Wait()
 
 		if task.Info.State != expect {
 			t.Errorf("state=%s", task.Info.State)
diff --git a/simulator/task_test.go b/simulator/task_test.go
index 502b2ff4..66257258 100644
--- a/simulator/task_test.go
+++ b/simulator/task_test.go
@@ -58,7 +58,7 @@ func TestNewTask(t *testing.T) {
 	add.fault = &types.ManagedObjectNotFound{}
 
 	task.Run(SpoofContext())
-	task.wait()
+	task.Wait()
 
 	if info.State != types.TaskInfoStateError {
 		t.Fail()