You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I have noticed a data race when my tests are using the vm.Relocate method for a folder change and for generating the datacenter event argument.
To Reproduce
Steps to reproduce the behavior:
I've tried to make a test case in virtual_machine_test.go, although I'm not sure if it is valid or not (I hit a couple kinds of races when I run):
func TestVmRelocate(t *testing.T) {
ctx := context.Background()
m := VPX()
defer m.Remove()
err := m.Create()
if err != nil {
t.Fatal(err)
}
s := m.Service.NewServer()
defer s.Close()
c, err := govmomi.NewClient(ctx, s.URL, true)
if err != nil {
t.Fatal(err)
}
vm := object.NewVirtualMachine(c.Client, Map.Any("VirtualMachine").Reference())
finder := find.NewFinder(c.Client, false)
dc, err := finder.DefaultDatacenter(ctx)
if err != nil {
t.Fatal(err)
}
finder.SetDatacenter(dc)
folders, err := dc.Folders(ctx)
if err != nil {
t.Fatal(err)
}
spec := types.VirtualMachineRelocateSpec{}
vmFolder := folders.VmFolder
for i := 0; i < 10; i++ {
vmFolderRef := vmFolder.Reference()
spec.Folder = &vmFolderRef
go func() {
task, err := vm.Relocate(ctx, spec, types.VirtualMachineMovePriorityDefaultPriority)
if err != nil {
t.Fatal("Failed to relocate", err)
}
_ = task.Wait(ctx)
}()
vmFolder, err = vmFolder.CreateFolder(ctx, "child")
if err != nil {
t.Fatal("Failed to create folder", err)
}
}
}
When I run go test -race -count=10 -run TestVmRelocate ./...
That tends to fail with either:
==================
WARNING: DATA RACE
Write at 0x000011f91d00 by goroutine 681:
github.com/vmware/govmomi/simulator.NewServiceInstance()
/Users/nathanp/govmomi/simulator/service_instance.go:39 +0x224
github.com/vmware/govmomi/simulator.(*Model).Create()
/Users/nathanp/govmomi/simulator/model.go:483 +0x144
github.com/vmware/govmomi/simulator.TestVmRelocate()
/Users/nathanp/govmomi/simulator/virtual_machine_test.go:1837 +0x3a6
testing.tRunner()
/usr/local/go/src/testing/testing.go:1689 +0x21e
testing.(*T).Run.gowrap1()
/usr/local/go/src/testing/testing.go:1742 +0x44
Previous read at 0x000011f91d00 by goroutine 653:
github.com/vmware/govmomi/simulator.datacenterEventArgument()
/Users/nathanp/govmomi/simulator/datacenter.go:142 +0x50
github.com/vmware/govmomi/simulator.(*VirtualMachine).RelocateVMTask.func1()
/Users/nathanp/govmomi/simulator/virtual_machine.go:2504 +0x128d
github.com/vmware/govmomi/simulator.(*Task).Run.func1()
/Users/nathanp/govmomi/simulator/task.go:130 +0x13b
Expected behavior
I don't expect a data race of the original (or first test reproduction). The latter one is maybe because each model is clobbering the other one when run concurrently? (just guessing)
Affected version
Please provide details on the version used, e.g. release tag, commit, module version, etc.
govmomi@v0.43.0
Screenshots/Debug Output
If applicable, add screenshots or debug output to help explain your problem.
This was the frames for the data race of the original reproduction
Describe the bug
I have noticed a data race when my tests are using the vm.Relocate method for a folder change and for generating the datacenter event argument.
To Reproduce
Steps to reproduce the behavior:
I've tried to make a test case in virtual_machine_test.go, although I'm not sure if it is valid or not (I hit a couple kinds of races when I run):
When I run
go test -race -count=10 -run TestVmRelocate ./...
That tends to fail with either:
Or
Expected behavior
I don't expect a data race of the original (or first test reproduction). The latter one is maybe because each model is clobbering the other one when run concurrently? (just guessing)
Affected version
Please provide details on the version used, e.g. release tag, commit, module version, etc.
govmomi@v0.43.0
Screenshots/Debug Output
If applicable, add screenshots or debug output to help explain your problem.
This was the frames for the data race of the original reproduction
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: