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 startTime = os.clock()
local deferredRefs = {} local deferredRefs = {}
local unappliedPatch = reifyInstance( local unappliedPatch =
deferredRefs, reifyInstance(deferredRefs, instanceMap, treeData.virtualInstances, treeData.rootId, container)
instanceMap,
treeData.virtualInstances,
treeData.rootId,
container
)
applyDeferredRefs(instanceMap, deferredRefs, unappliedPatch) applyDeferredRefs(instanceMap, deferredRefs, unappliedPatch)
local elapsed = os.clock() - startTime local elapsed = os.clock() - startTime

View file

@ -266,19 +266,34 @@ return function()
local knownIds = { rootId } 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 for _ = 1, 100 do
local operation = math.random(1, 3) local operation = math.random(1, 3)
if operation == 1 and #knownIds < 500 then 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)] local parentId = knownIds[math.random(1, #knownIds)]
local patch = PatchGenerator.createAdditionsPatch({ if instanceMap.fromIds[parentId] ~= nil then
count = 1, local patch = PatchGenerator.createAdditionsPatch({
parentId = parentId, count = 1,
}) parentId = parentId,
applyPatch(instanceMap, patch) })
for id in pairs(patch.added) do applyPatch(instanceMap, patch)
table.insert(knownIds, id) for id in pairs(patch.added) do
table.insert(knownIds, id)
end
end end
elseif operation == 2 and #knownIds > 1 then elseif operation == 2 and #knownIds > 1 then
-- Remove (not root) -- Remove (not root)
@ -288,16 +303,21 @@ return function()
local patch = PatchGenerator.createRemovalsPatch({ ids = { idToRemove } }) local patch = PatchGenerator.createRemovalsPatch({ ids = { idToRemove } })
applyPatch(instanceMap, patch) applyPatch(instanceMap, patch)
-- Clean up knownIds to remove any descendants that were destroyed
cleanupKnownIds()
elseif operation == 3 and #knownIds > 0 then elseif operation == 3 and #knownIds > 0 then
-- Update -- Update: verify instance still exists
local idToUpdate = knownIds[math.random(1, #knownIds)] local idToUpdate = knownIds[math.random(1, #knownIds)]
local patch = PatchSet.newEmpty() if instanceMap.fromIds[idToUpdate] ~= nil then
table.insert(patch.updated, { local patch = PatchSet.newEmpty()
id = idToUpdate, table.insert(patch.updated, {
changedName = "Updated_" .. tostring(os.clock()), id = idToUpdate,
changedProperties = {}, changedName = "Updated_" .. tostring(os.clock()),
}) changedProperties = {},
applyPatch(instanceMap, patch) })
applyPatch(instanceMap, patch)
end
end end
end end

View file

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

View file

@ -108,13 +108,14 @@ function MockApiContext:connect()
end end
-- Default connect response -- Default connect response
return true, { return true,
serverVersion = "0.0.0-mock", {
protocolVersion = 4, serverVersion = "0.0.0-mock",
sessionId = HttpService:GenerateGUID(false), protocolVersion = 4,
expectedPlaceIds = {}, sessionId = HttpService:GenerateGUID(false),
rootInstanceId = HttpService:GenerateGUID(false), expectedPlaceIds = {},
} rootInstanceId = HttpService:GenerateGUID(false),
}
end end
--[[ --[[