Skip to content

Commit

Permalink
fix: govc object.collect truncation
Browse files Browse the repository at this point in the history
In the PR #3331 refactor WaitOptions was changed to pass by value, rather than reference.
The Truncated value needs to be propagated from WaitForUpdatesEx response to the caller.

Fixes #3501
  • Loading branch information
dougm committed Aug 10, 2024
1 parent 5a501b5 commit 15d5ffd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
15 changes: 15 additions & 0 deletions govc/test/vcsim.bats
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ EOF
assert_matches "govmomi simulator"
}

@test "truncated WaitForUpdatesEx" {
total=142 # 100 is the default MaxObjectUpdates
vcsim_env -standalone-host 0 -vm $total

url="https://$(govc env GOVC_URL)"

model=$(curl -sfk "$url/debug/vars" | jq .vcsim.model)
vms=$(jq .machine <<<"$model")
assert_equal $total "$vms" # sanity check

run govc object.collect -type m / name
assert_success
[ ${#lines[@]} -eq "$total" ]
}

@test "vcsim host placement" {
vcsim_start -dc 0

Expand Down
2 changes: 1 addition & 1 deletion property/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (p *Collector) RetrieveOne(ctx context.Context, obj types.ManagedObjectRefe
// propagation.
func (p *Collector) WaitForUpdatesEx(
ctx context.Context,
opts WaitOptions,
opts *WaitOptions,
onUpdatesFn func([]types.ObjectUpdate) bool) error {

if !p.mu.TryLock() {
Expand Down
6 changes: 3 additions & 3 deletions property/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func ExampleCollector_WaitForUpdatesEx_addingRemovingPropertyFilters() {
go func() {
if err := pc.WaitForUpdatesEx(
cancelCtx,
property.WaitOptions{},
&property.WaitOptions{},
func(updates []types.ObjectUpdate) bool {
return waitForPowerStateChanges(
cancelCtx,
Expand Down Expand Up @@ -265,7 +265,7 @@ func ExampleCollector_WaitForUpdatesEx_errConcurrentCollector() {

waitForChanges := func(chanErr chan error) {
defer close(chanErr)
chanErr <- pc.WaitForUpdatesEx(ctx, waitOptions, onUpdatesFn)
chanErr <- pc.WaitForUpdatesEx(ctx, &waitOptions, onUpdatesFn)
}

// Start two goroutines that wait for changes, but only one will begin
Expand Down Expand Up @@ -296,7 +296,7 @@ func ExampleCollector_WaitForUpdatesEx_errConcurrentCollector() {

// The third WaitForUpdatesEx call should be able to successfully obtain
// the lock since the other two calls are completed.
if err := pc.WaitForUpdatesEx(ctx, waitOptions, onUpdatesFn); err != nil {
if err := pc.WaitForUpdatesEx(ctx, &waitOptions, onUpdatesFn); err != nil {
return fmt.Errorf(
"unexpected error from third call to WaitForUpdatesEx: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions property/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func WaitForUpdates(
return err
}

return pc.WaitForUpdatesEx(ctx, filter.WaitOptions, onUpdatesFn)
return pc.WaitForUpdatesEx(ctx, &filter.WaitOptions, onUpdatesFn)
}

// WaitForUpdates waits for any of the specified properties of the specified
Expand Down Expand Up @@ -166,5 +166,5 @@ func WaitForUpdatesEx(

}()

return pc.WaitForUpdatesEx(ctx, filter.WaitOptions, onUpdatesFn)
return pc.WaitForUpdatesEx(ctx, &filter.WaitOptions, onUpdatesFn)
}

0 comments on commit 15d5ffd

Please sign in to comment.