fix(startup): avoid reboot after shell exit
This commit is contained in:
parent
7b19de7945
commit
9fc474ce25
2
Justfile
2
Justfile
@ -114,7 +114,7 @@ test *args:
|
|||||||
rom_arg="--rom /Applications/CraftOS-PC.app/Contents/Resources"; \
|
rom_arg="--rom /Applications/CraftOS-PC.app/Contents/Resources"; \
|
||||||
fi; \
|
fi; \
|
||||||
repo='{{justfile_directory()}}'; \
|
repo='{{justfile_directory()}}'; \
|
||||||
mount_arg="--mount-ro /apis=$repo/apis --mount-ro /programs=$repo/programs --mount-ro /tests=$repo/tests"; \
|
mount_arg="--mount-ro /apis=$repo/apis --mount-ro /programs=$repo/programs --mount-ro /startup=$repo/startup --mount-ro /tests=$repo/tests"; \
|
||||||
tmp="$(mktemp)"; \
|
tmp="$(mktemp)"; \
|
||||||
data_dir="$(mktemp -d)"; \
|
data_dir="$(mktemp -d)"; \
|
||||||
output_path="$data_dir/computer/0/trapos-test-output"; \
|
output_path="$data_dir/computer/0/trapos-test-output"; \
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
local _VERSION = '1.3.0'
|
local _VERSION = '1.3.1'
|
||||||
|
|
||||||
local LOCAL_MANIFEST_PATH = '/trapos/manifest.json';
|
local LOCAL_MANIFEST_PATH = '/trapos/manifest.json';
|
||||||
|
|
||||||
@ -56,8 +56,3 @@ if #SERVERS > 0 then
|
|||||||
end
|
end
|
||||||
|
|
||||||
parallel.waitForAll(shellFn, table.unpack(servers));
|
parallel.waitForAll(shellFn, table.unpack(servers));
|
||||||
|
|
||||||
print("Servers stopped, reboot the machine...");
|
|
||||||
|
|
||||||
os.sleep(1);
|
|
||||||
os.reboot();
|
|
||||||
|
|||||||
70
tests/startup-servers.lua
Normal file
70
tests/startup-servers.lua
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
local createLibTest = require('/apis/libtest');
|
||||||
|
|
||||||
|
local testlib = createLibTest({ ... });
|
||||||
|
|
||||||
|
local function runStartupWithStubs()
|
||||||
|
local calls = {
|
||||||
|
rebooted = false,
|
||||||
|
shellRuns = {},
|
||||||
|
prints = {},
|
||||||
|
};
|
||||||
|
|
||||||
|
local env = setmetatable({
|
||||||
|
fs = {
|
||||||
|
exists = function(path)
|
||||||
|
return path ~= '/trapos/manifest.json' and fs.exists(path);
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
os = {
|
||||||
|
reboot = function()
|
||||||
|
calls.rebooted = true;
|
||||||
|
end,
|
||||||
|
sleep = function() end,
|
||||||
|
},
|
||||||
|
parallel = {
|
||||||
|
waitForAll = function(firstFn)
|
||||||
|
firstFn();
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
print = function(message)
|
||||||
|
calls.prints[#calls.prints + 1] = tostring(message);
|
||||||
|
end,
|
||||||
|
shell = {
|
||||||
|
path = function()
|
||||||
|
return '/rom/programs';
|
||||||
|
end,
|
||||||
|
run = function(program)
|
||||||
|
calls.shellRuns[#calls.shellRuns + 1] = program;
|
||||||
|
return true;
|
||||||
|
end,
|
||||||
|
setPath = function() end,
|
||||||
|
},
|
||||||
|
}, { __index = _G });
|
||||||
|
|
||||||
|
local chunk, loadErr = loadfile('/startup/servers.lua', 't', env);
|
||||||
|
if not chunk then
|
||||||
|
error(loadErr, 0);
|
||||||
|
end
|
||||||
|
|
||||||
|
local ok, err = pcall(chunk);
|
||||||
|
if not ok then
|
||||||
|
error(err, 0);
|
||||||
|
end
|
||||||
|
|
||||||
|
return calls;
|
||||||
|
end
|
||||||
|
|
||||||
|
testlib.test('shell exit does not force reboot', function()
|
||||||
|
local calls = runStartupWithStubs();
|
||||||
|
|
||||||
|
testlib.assertEquals(calls.shellRuns[1], 'shell');
|
||||||
|
testlib.assertEquals(calls.rebooted, false);
|
||||||
|
for _, message in ipairs(calls.prints) do
|
||||||
|
testlib.assertTrue(
|
||||||
|
not string.find(message, 'Servers stopped', 1, true),
|
||||||
|
'startup should not print a forced reboot message'
|
||||||
|
);
|
||||||
|
end
|
||||||
|
end);
|
||||||
|
|
||||||
|
testlib.run();
|
||||||
Loading…
Reference in New Issue
Block a user