cc-libs/tools/mcp-bridge/test-integration/lua/silent-client.lua

28 lines
659 B
Lua

-- Integration-test helper: connect, send a hello frame, then ignore every
-- request until the deadline expires. Used to prove the bridge's per-computer
-- probe timeout path.
local args = {...};
local id = tonumber(args[1]) or 99;
local label = args[2] or "silent";
local duration = tonumber(args[3]) or 5;
local url = "ws://127.0.0.1:2001/?id=" .. id;
local ws, err = http.websocket(url);
if not ws then
print("websocket failed: " .. tostring(err));
os.shutdown();
return;
end
ws.send(textutils.serializeJSON({
type = "hello",
computerId = id,
computerLabel = label,
}));
sleep(duration);
pcall(function() ws.close(); end);
os.shutdown();