mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Add duplicate update test
This commit is contained in:
parent
ec3584e7c2
commit
ff020bacb8
2 changed files with 99 additions and 3 deletions
|
|
@ -175,7 +175,7 @@ local function evaluate_node<T>(node: Node<T>, continue_on_error: boolean) -- if
|
||||||
if not ok then
|
if not ok then
|
||||||
local msg = debug.traceback(`effect error: {new_value}`, 2)
|
local msg = debug.traceback(`effect error: {new_value}`, 2)
|
||||||
if continue_on_error then
|
if continue_on_error then
|
||||||
task.spawn(error, msg, 0)
|
print(msg)
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
error(msg, 2)
|
error(msg, 2)
|
||||||
|
|
@ -199,7 +199,7 @@ local function evaluate_node<T>(node: Node<T>, continue_on_error: boolean) -- if
|
||||||
if not ok then
|
if not ok then
|
||||||
local msg = debug.traceback(`effect error: {new_value}`, 2)
|
local msg = debug.traceback(`effect error: {new_value}`, 2)
|
||||||
if continue_on_error then
|
if continue_on_error then
|
||||||
task.spawn(error, msg, 0)
|
print(msg)
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
error(msg, 2)
|
error(msg, 2)
|
||||||
|
|
@ -307,7 +307,7 @@ local function flush_update_queue(from: number)
|
||||||
update_queue_n = moveTo1
|
update_queue_n = moveTo1
|
||||||
if not changed then -- Can occur in recursive updates (where 'from' is > 0)
|
if not changed then -- Can occur in recursive updates (where 'from' is > 0)
|
||||||
if from == 0 then
|
if from == 0 then
|
||||||
warn("Some nodes failed to update", update_queue, node_deps_left, debug.traceback())
|
print("Some nodes failed to update", update_queue, node_deps_left, debug.traceback())
|
||||||
reset_queue()
|
reset_queue()
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -319,6 +319,102 @@ TEST("graph", function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
TEST("duplicate update", function()
|
||||||
|
local cases = {
|
||||||
|
{
|
||||||
|
name = "b",
|
||||||
|
err = "b",
|
||||||
|
e1 = {1, 2, 2, 2, 2},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "c",
|
||||||
|
err = "c",
|
||||||
|
e1 = {2, 1, 1, 2, 2},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "c2",
|
||||||
|
err = "c2",
|
||||||
|
e1 = {2, 2, 1, 2, 2},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "d",
|
||||||
|
err = "d",
|
||||||
|
e1 = {2, 2, 2, 1, 2},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "e",
|
||||||
|
err = "e",
|
||||||
|
e1 = {2, 2, 2, 2, 1},
|
||||||
|
e2 = {3, 3, 3, 3, 3}, -- e has a dependency on just 'a' after the first time, so it'll get updated 2x (only way to prevent this extra update is to yield, which isn't currently supported)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "no error",
|
||||||
|
err = "",
|
||||||
|
e1 = {2, 2, 2, 2, 2},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, case in cases do
|
||||||
|
CASE(case.name)
|
||||||
|
local destroy = root(function()
|
||||||
|
local e1, e2, err = case.e1, case.e2, case.err
|
||||||
|
if not e2 then
|
||||||
|
e2 = {}
|
||||||
|
for i, v in e1 do
|
||||||
|
e2[i] = v + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local a = source(0)
|
||||||
|
local nb = 0
|
||||||
|
local b = derive(function()
|
||||||
|
if err == "b" and a() == 1 then error("user error") end
|
||||||
|
nb += 1
|
||||||
|
return a() + 1
|
||||||
|
end)
|
||||||
|
local nc = 0
|
||||||
|
local c = derive(function()
|
||||||
|
if err == "c" and a() == 1 then error("user error") end
|
||||||
|
nc += 1
|
||||||
|
return a() * 2
|
||||||
|
end)
|
||||||
|
local nc2 = 0
|
||||||
|
local c2 = derive(function()
|
||||||
|
if err == "c2" and c() == 2 then error("user error") end
|
||||||
|
nc2 += 1
|
||||||
|
return c()
|
||||||
|
end)
|
||||||
|
local nd = 0
|
||||||
|
local d = derive(function()
|
||||||
|
if err == "d" and b() == 2 then error("user error") end
|
||||||
|
nd += 1
|
||||||
|
return b() * 100 + c2()
|
||||||
|
end)
|
||||||
|
local ne = 0
|
||||||
|
effect(function()
|
||||||
|
if err == "e" and a() == 1 then error("user error") end
|
||||||
|
ne += 1
|
||||||
|
a(); b(); c(); c2(); d()
|
||||||
|
end)
|
||||||
|
local length = graph.get_update_queue_length()
|
||||||
|
|
||||||
|
a(1)
|
||||||
|
CHECK(nb == e1[1])
|
||||||
|
CHECK(nc == e1[2])
|
||||||
|
CHECK(nc2 == e1[3])
|
||||||
|
CHECK(nd == e1[4])
|
||||||
|
CHECK(ne == e1[5])
|
||||||
|
CHECK(graph.get_update_queue_length() == length)
|
||||||
|
|
||||||
|
a(2)
|
||||||
|
CHECK(nb == e2[1])
|
||||||
|
CHECK(nc == e2[2])
|
||||||
|
CHECK(nc2 == e2[3])
|
||||||
|
CHECK(nd == e2[4])
|
||||||
|
CHECK(ne == e2[5])
|
||||||
|
end)
|
||||||
|
destroy()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
TEST("mount()", function()
|
TEST("mount()", function()
|
||||||
local screen = create "ScreenGui" {}
|
local screen = create "ScreenGui" {}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue