// npm import * as rp from 'request-promise'; import { Queue, Rrtq } from '@ownzones/rrtq'; import * as fs from 'fs'; import * as path from 'path'; import { Server } from 'http'; import { RedisClient } from 'redis'; import { config, log } from '../config'; import { Worker } from '../lib/workers/worker'; import { init } from '../server'; import { CacheManager, DynamodbCacheManager, ICacheManager, RedisCacheManager, } from '../lib/cache'; import { connectApiInit, createTokenVerifierMock, getOrCreateOrganization, IMockOrganization, } from './utils/zypline-mock'; import { ensureTestDynamoDBTable, flushDynamoDBTable } from './utils/dynamodb'; import { Driver } from '../driver'; import { LongWorker } from '../lib/workers/long-worker'; import { IJob } from '../lib/connect-api'; import { DeepPartial, GenericRequestPromise } from '../utils/types'; describe('Segment Endpoint', () => { let rrtq: Rrtq; let driverQueue: Queue; let mediaviewServer: { close: () => Promise }; let connectApi: Server; let driver: Driver; let longWorker: LongWorker; let cacheWorker: Worker; let cacheManagerInstance: ICacheManager; let organization: IMockOrganization; // eslint-disable-next-line mocha/no-hooks-for-single-case before(async () => { rrtq = new Rrtq({ redis: config.redis }); await (rrtq.redisClient as RedisClient).flushdbAsync(); cacheManagerInstance = CacheManager.getInstance(); cacheManagerInstance.startCacheGC(); if (cacheManagerInstance instanceof RedisCacheManager) { await cacheManagerInstance.options.client.flushdbAsync(); } else if (cacheManagerInstance instanceof DynamodbCacheManager) { await ensureTestDynamoDBTable(); await flushDynamoDBTable(); } driverQueue = await rrtq.createQueue( 'driver', { ...config.rrtq, namespace: config.rrtq.driverNamespace }, ); // start driver consumer driver = await Driver.create(config); longWorker = new LongWorker(config, config.rrtq.audioNamespaceChannelExtract); cacheWorker = new Worker(config, config.rrtq.videoNamespacePreCache); mediaviewServer = await init(createTokenVerifierMock(), 10 * 60 * 1000, 7); connectApi = connectApiInit(); organization = getOrCreateOrganization('test'); }); // eslint-disable-next-line mocha/no-hooks-for-single-case after(async () => { await driver.stop(); await rrtq.stop(); await cacheWorker.stop(); await longWorker.stop(); connectApi.close(); await mediaviewServer.close(); cacheManagerInstance.stopCacheGC(); CacheManager.destroyInstance(); }); it('should load audio segment with custom audio mapping from cache', async () => { const taskArgs = JSON.parse((fs.readFileSync(path.join(__dirname, 'files/comp-job.json'))).toString()) as DeepPartial; taskArgs.organization = organization; const task = await driverQueue.addTask(taskArgs); await task.waitForResponse(); const fileId = 'd6052a7a-0e8c-43b9-bb3c-c849fea1dac3'; // mono const monoMap = '%5B%5B%22196960b5-9715-47b6-8674-5036f3be38b7%22%2C%5B1%5D%2C%5B%22FC%22%5D%5D%5D&index=0'; // 5.1 const map5 = '%5B%5B%22196960b5-9715-47b6-8674-5036f3be38b7%22%2C%5B0%2C1%2C2%2C3%2C4%2C5%5D%2C%5B%22FL%22%2C%22FR%22%2C%22FC%22%2C%22LFE%22%2C%22BL%22%2C%22BR%22%5D%5D%5D&index=0'; let response = await (rp.get({ url: `http://localhost:3000/segment?fileId=${fileId}&virtualTrackId=customAudio&customAudioTrack=${monoMap}`, headers: { 'X-Organization-Slug': organization.slug, Authorization: 'Bearer smth smth smth', }, timeout: 10 * 60 * 1000, }) as GenericRequestPromise); log.info(`Length ${response.length}`); response = await (rp.get({ url: `http://localhost:3000/segment?fileId=${fileId}&virtualTrackId=customAudio&customAudioTrack=${map5}`, headers: { 'X-Organization-Slug': organization.slug, Authorization: 'Bearer smth smth smth', }, timeout: 10 * 60 * 1000, }) as GenericRequestPromise); log.info(`Length ${response.length}`); await organization.clearS3Cache(); }); });