Skip to content

Commit

Permalink
Merge pull request vmware#2069 from dougm/vcsim-list-view-race
Browse files Browse the repository at this point in the history
vcsim: avoid ViewManager.ModifyListView race
  • Loading branch information
dougm authored Jul 31, 2020
2 parents 0614f98 + 9cca13a commit 6bae3ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion simulator/race_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ func TestRace(t *testing.T) {
t.Fatal(err)
}

lv, err := view.NewManager(c.Client).CreateListView(ctx, nil)
if err != nil {
t.Fatal(err)
}

wg.Add(1)
collectors.Add(1)
go func() {
Expand Down Expand Up @@ -144,10 +149,11 @@ func TestRace(t *testing.T) {
defer wg.Done()

task, _ := f.VmFolder.CreateVM(ctx, cspec, pool, nil)
_, terr := task.WaitForResult(ctx, nil)
r, terr := task.WaitForResult(ctx, nil)
if terr != nil {
t.Error(terr)
}
_ = lv.Add(ctx, []types.ManagedObjectReference{r.Result.(types.ManagedObjectReference)})
}()
}

Expand Down Expand Up @@ -178,6 +184,7 @@ func TestRace(t *testing.T) {
time.AfterFunc(100*time.Millisecond, func() {
defer wg.Done()

_ = lv.Remove(ctx, []types.ManagedObjectReference{vm.Reference()})
task, _ := vm.PowerOff(ctx)
_ = task.Wait(ctx)
})
Expand Down
2 changes: 1 addition & 1 deletion simulator/view_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ type ListView struct {
}

func (v *ListView) update() {
Map.Update(v, []types.PropertyChange{{Name: "view", Val: v.View}})
Map.Update(v.Self, []types.PropertyChange{{Name: "view", Val: v.View}})
}

func (v *ListView) add(refs []types.ManagedObjectReference) *types.ManagedObjectNotFound {
Expand Down

0 comments on commit 6bae3ac

Please sign in to comment.