प्रकाशित सोर्स
सोर्स ZIP डाउनलोड करें
CH-J Server Manager
किसी विशेष ऐप्लिकेशन रिलीज़ की डायरेक्टरी और फ़ाइलें देखें।
CH-J / Server Manager
368 फ़ाइलें
core-20261017T201717Z-057348c4a70f
जोड़ा गया: तारीख दर्ज नहीं · बिल्ड किया गया:
1
"use strict";3
// Swapoff safety rule of the fixed remote swap helper, run locally with a fake /proc (no swap is touched).4
const test = require("node:test");5
const assert = require("node:assert/strict");6
const fs = require("node:fs");7
const os = require("node:os");8
const path = require("node:path");9
const { spawnSync } = require("node:child_process");11
const SCRIPT = path.join(__dirname, "../src/main/system/remoteSwap.sh");12
const MiB = 1024;13
// The helper is a POSIX shell script; Windows hosts have no /bin/sh.14
const skip = process.platform === "win32" ? "POSIX sh is not available on Windows." : false;16
function 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 }); }24
}26
test("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
});31
test("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
});35
test("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
});39
test("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
});45
test("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-256
308219b0336dacf85485ad2d9a4409f4a4ec37074c2393228dbd7967cb359ebcCH-J Proprietary Software License 1.14 · सोर्स CH-J Proprietary Software License 1.14 के तहत उपलब्ध कराया जाता है। इसकी उपलब्धता लाइसेंस की शर्तें नहीं बदलती और न ही अतिरिक्त अधिकार देती है।
आर्काइव SHA-256
cf4455b698f0f28e456a37b1834976a0194d8486acb7101052d59a838745cca3