Refactor stress test files for improved readability and functionality

- Simplified the reify stress test by consolidating the reifyInstance call into a single line for better clarity.
- Added a cleanup function in the stressPatterns test to manage knownIds, ensuring that IDs of destroyed instances are removed.
- Enhanced the logic for adding, removing, and updating instances in the stressPatterns test to verify the existence of parent and child instances before operations, improving test robustness.
- Reformatted code in LargeTreeGenerator and MockApiContext for consistency and readability.
This commit is contained in:
Joe 2026-02-01 22:10:18 -06:00
parent 01110fc916
commit d513ab16c0
4 changed files with 48 additions and 31 deletions

View file

@ -527,13 +527,8 @@ return function()
local startTime = os.clock()
local deferredRefs = {}
local unappliedPatch = reifyInstance(
deferredRefs,
instanceMap,
treeData.virtualInstances,
treeData.rootId,
container
)
local unappliedPatch =
reifyInstance(deferredRefs, instanceMap, treeData.virtualInstances, treeData.rootId, container)
applyDeferredRefs(instanceMap, deferredRefs, unappliedPatch)
local elapsed = os.clock() - startTime

View file

@ -266,12 +266,26 @@ return function()
local knownIds = { rootId }
-- Helper to clean up knownIds by removing IDs that no longer exist in instanceMap.
-- This is necessary because when a parent is removed, its children are also
-- destroyed by Roblox, but their IDs may still be in knownIds.
local function cleanupKnownIds()
local validIds = {}
for _, id in ipairs(knownIds) do
if instanceMap.fromIds[id] ~= nil then
table.insert(validIds, id)
end
end
knownIds = validIds
end
for _ = 1, 100 do
local operation = math.random(1, 3)
if operation == 1 and #knownIds < 500 then
-- Add
-- Add: verify parent still exists (may have been destroyed as descendant)
local parentId = knownIds[math.random(1, #knownIds)]
if instanceMap.fromIds[parentId] ~= nil then
local patch = PatchGenerator.createAdditionsPatch({
count = 1,
parentId = parentId,
@ -280,6 +294,7 @@ return function()
for id in pairs(patch.added) do
table.insert(knownIds, id)
end
end
elseif operation == 2 and #knownIds > 1 then
-- Remove (not root)
local indexToRemove = math.random(2, #knownIds)
@ -288,9 +303,13 @@ return function()
local patch = PatchGenerator.createRemovalsPatch({ ids = { idToRemove } })
applyPatch(instanceMap, patch)
-- Clean up knownIds to remove any descendants that were destroyed
cleanupKnownIds()
elseif operation == 3 and #knownIds > 0 then
-- Update
-- Update: verify instance still exists
local idToUpdate = knownIds[math.random(1, #knownIds)]
if instanceMap.fromIds[idToUpdate] ~= nil then
local patch = PatchSet.newEmpty()
table.insert(patch.updated, {
id = idToUpdate,
@ -300,6 +319,7 @@ return function()
applyPatch(instanceMap, patch)
end
end
end
instanceMap:stop()
end)

View file

@ -208,7 +208,8 @@ function LargeTreeGenerator.createVirtualTree(options)
if withDuplicates and currentDepth <= 1 then
for _ = 1, duplicateCount do
local duplicateName = prefix .. "_1" -- Same as first child
local duplicateId = createVirtualInstance(duplicateName, id, currentDepth + 1, duplicateName .. "_dup")
local duplicateId =
createVirtualInstance(duplicateName, id, currentDepth + 1, duplicateName .. "_dup")
table.insert(children, duplicateId)
end
end

View file

@ -108,7 +108,8 @@ function MockApiContext:connect()
end
-- Default connect response
return true, {
return true,
{
serverVersion = "0.0.0-mock",
protocolVersion = 4,
sessionId = HttpService:GenerateGUID(false),