Skip to content

simulator: add PropertyDiff, Context helpers, and AutoUpdate pattern#4013

Open
hickeng wants to merge 1 commit into
vmware:mainfrom
hickeng:pr1/propertydiff-autoupdate
Open

simulator: add PropertyDiff, Context helpers, and AutoUpdate pattern#4013
hickeng wants to merge 1 commit into
vmware:mainfrom
hickeng:pr1/propertydiff-autoupdate

Conversation

@hickeng
Copy link
Copy Markdown
Contributor

@hickeng hickeng commented May 12, 2026

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 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. This helps avoid data races
    with concurrent updates via VMOMI API.

How Has This Been Tested?

Unit and sim testing:

  • simple/nested/slice field changes
  • Add/Remove transitions
  • embedded wrapper types (TestCheckpoint)
  • the PropertyCollector integration (TestPropertyDiff_WithSimulator, TestContext_AutoUpdate)
  • concurrent-access safety (TestPropertyDiff_ConcurrentAccess)

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>
@hickeng hickeng requested a review from dougm May 12, 2026 18:51
@hickeng hickeng marked this pull request as ready for review May 12, 2026 18:51
@hickeng hickeng requested a review from akutz May 13, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant