simulator: add PropertyDiff, Context helpers, and AutoUpdate pattern#4013
Open
hickeng wants to merge 1 commit into
Open
simulator: add PropertyDiff, Context helpers, and AutoUpdate pattern#4013hickeng wants to merge 1 commit into
hickeng wants to merge 1 commit into
Conversation
Add PropertyDiff utility for granular property change tracking and
three new helpers on *Context that eliminate the error-prone manual
lock/snapshot/diff/publish pattern:
PropertyDiff(checkpoint, obj) – diffs old vs current managed-object
state and returns []types.PropertyChange with correct Op values
(Assign/Add/Remove). Handles nested structs, embedded fields, and
slices. getManagedObject() extracts the embedded mo.* value from
any simulator wrapper type so callers pass the simulator object
directly.
ctx.Checkpoint(obj) – take a locked snapshot (deep copy)
of obj's mo state; returns mo.Reference.
ctx.UpdateDiff(old, obj) – diff old vs current obj (under lock)
and publish via ctx.Update.
ctx.AutoUpdate(obj, mutateFn) – acquire the lock once, snapshot,
call mutateFn under the lock, diff, and publish. Preferred pattern
for in-handler mutations.
Tests cover simple/nested/slice field changes, Add/Remove transitions,
embedded wrapper types (TestCheckpoint), the PropertyCollector
integration (TestPropertyDiff_WithSimulator, TestContext_AutoUpdate),
and concurrent-access safety (TestPropertyDiff_ConcurrentAccess).
AI-Tool-Used: Cursor
AI-Tool-Use-Level: medium
AI-Code-Category: non-production
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: George Hicken <george.hicken@broadcom.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add PropertyDiff capability for granular property change tracking and .
PropertyDiff– diffs old vs current managed-object state and returns[]types.PropertyChange with correct Op values (Assign/Add/Remove).
Handles nested structs, embedded fields, and slices.
ctx.Checkpoint(obj)– take a locked snapshot (deep copy) of obj's mostate; returns mo.Reference.
ctx.UpdateDiff(old, obj)– diff old vs current obj (under lock) and publishvia ctx.Update.
mutateFn under the lock, diff, and publish. This helps avoid data races
with concurrent updates via VMOMI API.
How Has This Been Tested?
Unit and sim testing: