mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-17 10:00:46 -04:00
converge everything into one data folder
This commit is contained in:
@@ -5,7 +5,7 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { spawn } = require('child_process');
|
||||
const yaml = require('js-yaml');
|
||||
const { resolveDataPath } = require('../../helpers/dataPaths');
|
||||
const { resolveDataDir, resolveDataPath } = require('../../helpers/dataPaths');
|
||||
const { buildMediaMtxConfig } = require('./config');
|
||||
|
||||
function createMediaMtxSupervisor(deps) {
|
||||
@@ -52,6 +52,16 @@ function createMediaMtxSupervisor(deps) {
|
||||
logger.info(`Starting MediaMTX with generated config ${configPath}`);
|
||||
child = spawnProcess(mediaMtxBin, [configPath], {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
/*
|
||||
MediaMTX passes its environment to runOnReady hooks. Supplying the
|
||||
resolved value here also covers development starts where
|
||||
SERVER_DATA_DIR was omitted, so the installed snapshot writer and every
|
||||
Node snapshot reader still converge on the same canonical data root.
|
||||
*/
|
||||
env: {
|
||||
...process.env,
|
||||
SERVER_DATA_DIR: resolveDataDir(),
|
||||
},
|
||||
});
|
||||
|
||||
forwardLines(child.stdout, 'info');
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
// MediaMTX Supervisor Tests
|
||||
// Purpose: Verifies that generated MediaMTX state and child hooks inherit the server's single data root.
|
||||
// Scope: Uses a child-process double and a temporary directory; no listener or background process is started.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const EventEmitter = require('events');
|
||||
const { PassThrough } = require('stream');
|
||||
const { createMediaMtxSupervisor } = require('./supervisor');
|
||||
|
||||
test('passes the resolved data root to MediaMTX runOnReady hooks', () => {
|
||||
const temporaryDataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'multirover-mediamtx-supervisor-'));
|
||||
const generatedConfigPath = path.join(temporaryDataDir, 'mediamtx.yml');
|
||||
const previousDataDir = process.env.SERVER_DATA_DIR;
|
||||
let invocation = null;
|
||||
|
||||
process.env.SERVER_DATA_DIR = temporaryDataDir;
|
||||
|
||||
const spawnProcess = (command, args, options) => {
|
||||
const child = new EventEmitter();
|
||||
child.stdout = new PassThrough();
|
||||
child.stderr = new PassThrough();
|
||||
child.kill = (signal) => {
|
||||
child.emit('exit', 0, signal);
|
||||
};
|
||||
invocation = { command, args, options };
|
||||
return child;
|
||||
};
|
||||
|
||||
const logger = {
|
||||
info() {},
|
||||
warn() {},
|
||||
error() {},
|
||||
};
|
||||
|
||||
try {
|
||||
const supervisor = createMediaMtxSupervisor({
|
||||
config: { media: { additionalHosts: ['media.example.test'] } },
|
||||
serverPort: 8080,
|
||||
logger,
|
||||
mediaMtxBin: '/test/bin/mediamtx',
|
||||
snapshotWriterPath: '/test/bin/rover-snapshot-writer',
|
||||
configPath: generatedConfigPath,
|
||||
spawnProcess,
|
||||
});
|
||||
|
||||
supervisor.start();
|
||||
|
||||
assert.equal(invocation.command, '/test/bin/mediamtx');
|
||||
assert.deepEqual(invocation.args, [generatedConfigPath]);
|
||||
assert.equal(invocation.options.env.SERVER_DATA_DIR, temporaryDataDir);
|
||||
assert.equal(fs.existsSync(generatedConfigPath), true);
|
||||
|
||||
supervisor.stop();
|
||||
} finally {
|
||||
/*
|
||||
Restore process-global state and delete only the test-owned directory so a
|
||||
failed assertion cannot alter later tests or leave generated YAML behind.
|
||||
*/
|
||||
if (previousDataDir === undefined) delete process.env.SERVER_DATA_DIR;
|
||||
else process.env.SERVER_DATA_DIR = previousDataDir;
|
||||
fs.rmSync(temporaryDataDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user