std.sql.exec("CREATE TABLE IF NOT EXISTS t5 (x INTEGER)")
local t0 = std.time.millis()
local ok_sql = pcall(function()
std.task.with_timeout(100, function(scope)
local h = scope:spawn(function()
return std.sql.query([[
WITH RECURSIVE c(x) AS (
SELECT 1 UNION ALL SELECT x+1 FROM c WHERE x < 1000000000
)
SELECT count(*) AS n FROM c
]])
end)
h:join()
end)
end)
local elapsed_sql = std.time.millis() - t0
print("sql_cancel_raises=" .. tostring(not ok_sql))
print("sql_cancel_bounded=" .. tostring(elapsed_sql < 2000))
local ok_sql_b, err_sql_b = pcall(function()
std.task.scope(function(scope)
local h = scope:spawn(function()
return std.sql.query([[
WITH RECURSIVE c(x) AS (
SELECT 1 UNION ALL SELECT x+1 FROM c WHERE x < 1000000000
)
SELECT count(*) AS n FROM c
]])
end)
scope:spawn(function()
std.task.sleep(100)
scope:cancel()
end)
return h:join()
end)
end)
local err_sql_str = tostring(err_sql_b)
print("sql_cancel_raises_b=" .. tostring(not ok_sql_b))
print("sql_cancel_err_match=" .. tostring(
string.find(err_sql_str, "task cancelled during sql.query", 1, true) ~= nil
))
print("sql_cancel_no_hybrid=" .. tostring(
string.find(err_sql_str, "during sql sql", 1, true) == nil
))
local t1 = std.time.millis()
local ok_kv = pcall(function()
std.task.with_timeout(50, function(scope)
local h = scope:spawn(function()
for i = 1, 10000 do
std.kv.set("phase5", "k" .. i, tostring(i))
end
end)
h:join()
end)
end)
local elapsed_kv = std.time.millis() - t1
print("kv_cancel_raises=" .. tostring(not ok_kv))
print("kv_cancel_bounded=" .. tostring(elapsed_kv < 2000))
local ok_kv_b, err_kv_b = pcall(function()
std.task.scope(function(scope)
local h = scope:spawn(function()
for i = 1, 100000 do
std.kv.set("phase5b", "k" .. i, tostring(i))
end
end)
scope:spawn(function()
std.task.sleep(50)
scope:cancel()
end)
return h:join()
end)
end)
local err_kv_str = tostring(err_kv_b)
print("kv_cancel_raises_b=" .. tostring(not ok_kv_b))
print("kv_cancel_err_match=" .. tostring(
string.find(err_kv_str, "task cancelled during kv.set", 1, true) ~= nil
))
print("kv_cancel_no_hybrid=" .. tostring(
string.find(err_kv_str, "during sql kv", 1, true) == nil
))
std.kv.set("phase5", "plain", "ok")
local v = std.kv.get("phase5", "plain")
print("kv_plain_ok=" .. tostring(v == "ok"))
std.sql.exec("INSERT INTO t5 (x) VALUES (?)", { 1 })
local rows = std.sql.query("SELECT x FROM t5 WHERE x = ?", { 1 })
print("sql_plain_ok=" .. tostring(rows[1].x == 1))
local t2 = std.time.millis()
local results = {}
std.task.scope(function(scope)
local handles = {}
for i = 1, 5 do
handles[i] = scope:spawn(function()
std.kv.set("phase5_fan", "k" .. i, "v" .. i)
return std.kv.get("phase5_fan", "k" .. i)
end)
end
for i = 1, 5 do
results[i] = handles[i]:join()
end
end)
local elapsed_fan = std.time.millis() - t2
print("fan_all_joined=" .. tostring(#results == 5))
print("fan_values_ok=" .. tostring(results[1] == "v1" and results[5] == "v5"))
print("fan_bounded=" .. tostring(elapsed_fan < 2000))
print("done")