CH-J Server Managerserverio valdymas per SSH
Meniu
Paskelbtas šaltinis

CH-J Server Manager

Naršyti aplankus ir failus konkrečiai programai išleisti.

Atsisiųsti šaltinį ZIP
CH-J / Server Manager 368 failai
core-20261017T201717Z-057348c4a70f Pridėta: Data neregistruota · Pastatytas:
remoteSwap.test.js Pridėta: Data neregistruota 2.7 KB · 48 eilutės
Kodas Atsiųsti failą
1"use strict";
3// Swapoff safety rule of the fixed remote swap helper, run locally with a fake /proc (no swap is touched).
4const test = require("node:test");
5const assert = require("node:assert/strict");
6const fs = require("node:fs");
7const os = require("node:os");
8const path = require("node:path");
9const { spawnSync } = require("node:child_process");
11const SCRIPT = path.join(__dirname, "../src/main/system/remoteSwap.sh");
12const MiB = 1024;
13// The helper is a POSIX shell script; Windows hosts have no /bin/sh.
14const skip = process.platform === "win32" ? "POSIX sh is not available on Windows." : false;
16function check({ totalMiB, availableMiB, areas }) {
17 const proc = fs.mkdtempSync(path.join(os.tmpdir(), "chj-swap-proc-"));
18 try {
19 fs.writeFileSync(path.join(proc, "meminfo"), `MemTotal: ${totalMiB * MiB} kB\nMemAvailable: ${availableMiB * MiB} kB\n`);
20 fs.writeFileSync(path.join(proc, "swaps"), "Filename\tType\tSize\tUsed\tPriority\n" + areas.map(([name, sizeMiB, usedMiB]) => `${name}\tfile\t${sizeMiB * MiB}\t${usedMiB * MiB}\t-2`).join("\n") + "\n");
21 const result = spawnSync("sh", [SCRIPT, "safety-check", areas[0][0]], { encoding: "utf8", env: { ...process.env, CHJ_SWAP_TEST_PROC: proc } });
22 return result.stdout.includes("safe\n") ? "safe" : (result.stdout.match(/CHJ_ERR=(\w+)/) || [])[1];
23 } finally { fs.rmSync(proc, { recursive: true, force: true }); }
26test("swapoff is refused when the used swap cannot fit into RAM minus the reserve", { skip }, () => {
27 assert.equal(check({ totalMiB: 4096, availableMiB: 1024, areas: [["/swapfile", 2048, 900]] }), "SWAPOFF_UNSAFE");
28 assert.equal(check({ totalMiB: 4096, availableMiB: 1024, areas: [["/swapfile", 2048, 400]] }), "safe");
29});
31test("free space in other active swap areas counts towards the room", { skip }, () => {
32 assert.equal(check({ totalMiB: 4096, availableMiB: 1024, areas: [["/swapfile", 2048, 900], ["/swap/b", 1024, 0]] }), "safe");
33});
35test("an unused swap area can always be deactivated, even on a small server", { skip }, () => {
36 assert.equal(check({ totalMiB: 468, availableMiB: 408, areas: [["/swapfile", 128, 0]] }), "safe");
37});
39test("the reserve never exceeds a quarter of RAM on small servers", { skip }, () => {
40 // 468 MiB RAM: reserve 117 MiB instead of 512 MiB.
41 assert.equal(check({ totalMiB: 468, availableMiB: 400, areas: [["/swapfile", 256, 200]] }), "safe");
42 assert.equal(check({ totalMiB: 468, availableMiB: 300, areas: [["/swapfile", 256, 200]] }), "SWAPOFF_UNSAFE");
43});
45test("the test-only operation is unavailable without the test /proc override", { skip }, () => {
46 const result = spawnSync("sh", [SCRIPT, "safety-check", "/swapfile"], { encoding: "utf8", env: { PATH: process.env.PATH } });
47 assert.match(result.stdout, /CHJ_ERR=ACTION_INVALID/);
48});
SHA-256308219b0336dacf85485ad2d9a4409f4a4ec37074c2393228dbd7967cb359ebc

CH-J Proprietary Software License 1.14 · Šaltinis pateiktas pagal CH-J Proprietary Software License 1.14. Jo prieinamumas nekeičia licencijos sąlygų ir nesuteikia papildomų teisių.

Archyvas SHA-256cf4455b698f0f28e456a37b1834976a0194d8486acb7101052d59a838745cca3
Failai