From 15d5ffdb3078fc34c1f0905e9554ef0495676c87 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 9 Aug 2024 20:19:44 -0700 Subject: [PATCH] fix: govc object.collect truncation 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 --- govc/test/vcsim.bats | 15 +++++++++++++++ property/collector.go | 2 +- property/example_test.go | 6 +++--- property/wait.go | 4 ++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/govc/test/vcsim.bats b/govc/test/vcsim.bats index 3828fda57..7b5bcbe05 100755 --- a/govc/test/vcsim.bats +++ b/govc/test/vcsim.bats @@ -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 diff --git a/property/collector.go b/property/collector.go index 263621a06..9ee78d0d3 100644 --- a/property/collector.go +++ b/property/collector.go @@ -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() { diff --git a/property/example_test.go b/property/example_test.go index 5621e4002..8ddc94e26 100644 --- a/property/example_test.go +++ b/property/example_test.go @@ -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, @@ -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 @@ -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) } diff --git a/property/wait.go b/property/wait.go index 07ea3cb5d..dae7bf383 100644 --- a/property/wait.go +++ b/property/wait.go @@ -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 @@ -166,5 +166,5 @@ func WaitForUpdatesEx( }() - return pc.WaitForUpdatesEx(ctx, filter.WaitOptions, onUpdatesFn) + return pc.WaitForUpdatesEx(ctx, &filter.WaitOptions, onUpdatesFn) }