56 lines
3.3 KiB
JavaScript
56 lines
3.3 KiB
JavaScript
// Cas limites de getStream : binaire absent, annulation avant les données (avec copie de cookies), URL refusée
|
|
const fs = require('fs');
|
|
const { SCRATCH, __glob, isolateData, check, done, req, chopinTmpDirs } = require('./_setup');
|
|
const dataDir = isolateData('edge');
|
|
const youtube = req('src/youtube');
|
|
const { getStream, activeProcesses } = req('src/player/Method/Youtube.js');
|
|
const { cookies, settings, ytdlp, diagnostics } = youtube;
|
|
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
const song = { id: 'edge', title: 'edge', url: 'https://www.youtube.com/watch?v=jNQXAC9IVRw', type: 'youtube' };
|
|
|
|
(async () => {
|
|
console.log('# URL refusée');
|
|
check('URL "--exec=..." refusée', (await getStream({ url: '--exec=calc' })) === null);
|
|
|
|
console.log('# Binaire absent');
|
|
const savedPath = process.env.PATH, savedRoot = __glob.ROOT;
|
|
process.env.PATH = '';
|
|
__glob.ROOT = SCRATCH + '/';
|
|
const bin = ytdlp.resolveBinary({ force: true });
|
|
check('resolveBinary -> missing', bin.source === 'missing', bin);
|
|
const n0 = diagnostics.getRecent(100).length;
|
|
const r1 = await getStream(song, 0, { guildId: 'g' });
|
|
const last = diagnostics.getRecent(1)[0];
|
|
check('binaire absent : null, 1 tentative, BINARY_MISSING', r1 === null && diagnostics.getRecent(100).length - n0 === 1 && last.cls === 'BINARY_MISSING', last);
|
|
process.env.PATH = savedPath;
|
|
__glob.ROOT = savedRoot;
|
|
check('binaire retrouvé ensuite', ytdlp.resolveBinary({ force: true }).source !== 'missing');
|
|
|
|
console.log('# Annulation avant les données (avec compte : copie de cookies)');
|
|
const T = (...f) => f.join('\t');
|
|
cookies.importCookies([T('.youtube.com', 'TRUE', '/', 'TRUE', 1830000000, 'LOGIN_INFO', 'fake'), T('.youtube.com', 'TRUE', '/', 'TRUE', 1830000000, 'SAPISID', 'fake')].join('\n'));
|
|
settings.update({ cookiesMode: 'always' });
|
|
const controller = new AbortController();
|
|
const p = getStream(song, 0, { signal: controller.signal, guildId: 'g2' });
|
|
await sleep(400);
|
|
const copiesDuring = cookies.liveCopyCount();
|
|
const procDuring = ytdlp.activeCount();
|
|
controller.abort();
|
|
const r2 = await p;
|
|
console.log(` pendant : copies ${copiesDuring}, processus ${procDuring}`);
|
|
check('annulation : null', r2 === null);
|
|
check('annulation : diagnostics "aborted"', diagnostics.getRecent(1)[0].outcome === 'aborted');
|
|
let waited = 0;
|
|
while ((ytdlp.activeCount() || cookies.liveCopyCount() || chopinTmpDirs().length) && waited < 5000) { await sleep(100); waited += 100; }
|
|
console.log(` après ${waited} ms : processus ${ytdlp.activeCount()}, copies ${cookies.liveCopyCount()}, dossiers ${chopinTmpDirs().length}, activeProcesses ${activeProcesses.size}`);
|
|
check('annulation : la copie existait pendant la tentative', copiesDuring === 1 && procDuring >= 1);
|
|
check('annulation : processus tués, copie supprimée', ytdlp.activeCount() === 0 && cookies.liveCopyCount() === 0 && chopinTmpDirs().length === 0 && activeProcesses.size === 0);
|
|
|
|
console.log('# Signal déjà annulé');
|
|
const c2 = new AbortController(); c2.abort();
|
|
check('signal déjà annulé : null sans processus', (await getStream(song, 0, { signal: c2.signal })) === null && ytdlp.activeCount() === 0);
|
|
|
|
fs.rmSync(dataDir, { recursive: true, force: true });
|
|
done();
|
|
})().catch((e) => { console.error(e); process.exitCode = 1; });
|