mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
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:
parent
01110fc916
commit
d513ab16c0
4 changed files with 48 additions and 31 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -266,19 +266,34 @@ 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)]
|
||||
local patch = PatchGenerator.createAdditionsPatch({
|
||||
count = 1,
|
||||
parentId = parentId,
|
||||
})
|
||||
applyPatch(instanceMap, patch)
|
||||
for id in pairs(patch.added) do
|
||||
table.insert(knownIds, id)
|
||||
if instanceMap.fromIds[parentId] ~= nil then
|
||||
local patch = PatchGenerator.createAdditionsPatch({
|
||||
count = 1,
|
||||
parentId = parentId,
|
||||
})
|
||||
applyPatch(instanceMap, patch)
|
||||
for id in pairs(patch.added) do
|
||||
table.insert(knownIds, id)
|
||||
end
|
||||
end
|
||||
elseif operation == 2 and #knownIds > 1 then
|
||||
-- Remove (not root)
|
||||
|
|
@ -288,16 +303,21 @@ 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)]
|
||||
local patch = PatchSet.newEmpty()
|
||||
table.insert(patch.updated, {
|
||||
id = idToUpdate,
|
||||
changedName = "Updated_" .. tostring(os.clock()),
|
||||
changedProperties = {},
|
||||
})
|
||||
applyPatch(instanceMap, patch)
|
||||
if instanceMap.fromIds[idToUpdate] ~= nil then
|
||||
local patch = PatchSet.newEmpty()
|
||||
table.insert(patch.updated, {
|
||||
id = idToUpdate,
|
||||
changedName = "Updated_" .. tostring(os.clock()),
|
||||
changedProperties = {},
|
||||
})
|
||||
applyPatch(instanceMap, patch)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -108,13 +108,14 @@ function MockApiContext:connect()
|
|||
end
|
||||
|
||||
-- Default connect response
|
||||
return true, {
|
||||
serverVersion = "0.0.0-mock",
|
||||
protocolVersion = 4,
|
||||
sessionId = HttpService:GenerateGUID(false),
|
||||
expectedPlaceIds = {},
|
||||
rootInstanceId = HttpService:GenerateGUID(false),
|
||||
}
|
||||
return true,
|
||||
{
|
||||
serverVersion = "0.0.0-mock",
|
||||
protocolVersion = 4,
|
||||
sessionId = HttpService:GenerateGUID(false),
|
||||
expectedPlaceIds = {},
|
||||
rootInstanceId = HttpService:GenerateGUID(false),
|
||||
}
|
||||
end
|
||||
|
||||
--[[
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue