diff --git a/shared/packages/api/src/lib.ts b/shared/packages/api/src/lib.ts index db50e241..47bccfa7 100644 --- a/shared/packages/api/src/lib.ts +++ b/shared/packages/api/src/lib.ts @@ -57,10 +57,10 @@ export async function promiseTimeout( timeoutTime: number, timeoutMessage?: string | ((timeoutDuration: number) => string) ): Promise { - const startTime = Date.now() + const timer = startTimer() return new Promise((resolve, reject) => { const timeout = setTimeout(() => { - const duration = Date.now() - startTime + const duration = timer.get() const msg = typeof timeoutMessage === 'function' ? timeoutMessage(duration) : timeoutMessage reject(msg || 'Timeout') }, timeoutTime) @@ -343,3 +343,21 @@ export function findValue(map: Map, cb: (key: K, value: V) => boolea if (found === undefined) return undefined return found[1] } +/** + * Usage: + * const timer = startTimer() + * // do stuff + * const duration = timer.get() + */ +export function startTimer(): { + /** Returns the duration since the timer started, in milliseconds */ + get: () => number +} { + const startTime = Date.now() + + return { + get: () => { + return Date.now() - startTime + }, + } +} diff --git a/shared/packages/expectationManager/src/evaluationRunner/evaluationRunner.ts b/shared/packages/expectationManager/src/evaluationRunner/evaluationRunner.ts index d6054c3b..04c1ed77 100644 --- a/shared/packages/expectationManager/src/evaluationRunner/evaluationRunner.ts +++ b/shared/packages/expectationManager/src/evaluationRunner/evaluationRunner.ts @@ -10,6 +10,7 @@ import { Reason, StatusCode, stringifyError, + startTimer, } from '@sofie-package-manager/api' import { PromisePool } from '@supercharge/promise-pool' import _ from 'underscore' @@ -38,29 +39,41 @@ export class EvaluationRunner { public async run(): Promise { this.logger.debug(Date.now() / 1000 + ' _evaluateExpectations ----------') - let startTime = Date.now() const times: { [key: string]: number } = {} - // First we're going to see if there is any new incoming data which needs to be pulled in. - if (this.tracker.receivedUpdates.expectationsHasBeenUpdated) { - await this.updateReceivedData_Expectations().promise + { + const timer = startTimer() + + // First we're going to see if there is any new incoming data which needs to be pulled in. + if (this.tracker.receivedUpdates.expectationsHasBeenUpdated) { + await this.updateReceivedData_Expectations().promise + } + times['timeUpdateReceivedExpectations'] = timer.get() } - times['timeUpdateReceivedExpectations'] = Date.now() - startTime - startTime = Date.now() - if (this.tracker.receivedUpdates.packageContainersHasBeenUpdated) { - await this._updateReceivedData_TrackedPackageContainers() + { + const timer = startTimer() + + if (this.tracker.receivedUpdates.packageContainersHasBeenUpdated) { + await this._updateReceivedData_TrackedPackageContainers() + } + times['timeUpdateReceivedPackageContainerExpectations'] = timer.get() } - times['timeUpdateReceivedPackageContainerExpectations'] = Date.now() - startTime - startTime = Date.now() - // Iterate through the PackageContainerExpectations: - await this._evaluateAllTrackedPackageContainers() - times['timeEvaluateAllTrackedPackageContainers'] = Date.now() - startTime - startTime = Date.now() + { + const timer = startTimer() - this.tracker.worksInProgress.checkWorksInProgress() - times['timeMonitorWorksInProgress'] = Date.now() - startTime + // Iterate through the PackageContainerExpectations: + await this._evaluateAllTrackedPackageContainers() + times['timeEvaluateAllTrackedPackageContainers'] = timer.get() + } + + { + const timer = startTimer() + + this.tracker.worksInProgress.checkWorksInProgress() + times['timeMonitorWorksInProgress'] = timer.get() + } // Iterate through all Expectations: const { runAgainASAP, times: evaluateTimes } = await this._evaluateAllExpectations() @@ -298,7 +311,7 @@ export class EvaluationRunner { // Step 1: Evaluate the Expectations which are in the states that can be handled in parallel: for (const handleState of handleStatesParallel) { - const startTime = Date.now() + const timer = startTimer() // Filter out the ones that are in the state we're about to handle: const trackedWithState = tracked.filter((trackedExp) => trackedExp.state === handleState) @@ -324,7 +337,7 @@ export class EvaluationRunner { postProcessSession(trackedExp) }) } - times[`time_${handleState}`] = Date.now() - startTime + times[`time_${handleState}`] = timer.get() } // Step 1.5: Reset the session: @@ -340,7 +353,7 @@ export class EvaluationRunner { }) this.logger.debug(`Worker count: ${this.manager.workerAgents.list().length}`) - const startTime = Date.now() + const timer = startTimer() // Step 2: Evaluate the expectations, now one by one: for (const trackedExp of tracked) { // Only handle the states that @@ -350,7 +363,7 @@ export class EvaluationRunner { postProcessSession(trackedExp) } - if (runAgainASAP && Date.now() - startTime > this.tracker.constants.ALLOW_SKIPPING_QUEUE_TIME) { + if (runAgainASAP && timer.get() > this.tracker.constants.ALLOW_SKIPPING_QUEUE_TIME) { // Skip the rest of the queue, so that we don't get stuck on evaluating low-prio expectations. this.logger.debug( `Skipping the rest of the queue (after ${this.tracker.constants.ALLOW_SKIPPING_QUEUE_TIME})` @@ -365,7 +378,7 @@ export class EvaluationRunner { break } } - times[`time_restTrackedExp`] = Date.now() - startTime + times[`time_restTrackedExp`] = timer.get() for (const id of removeIds) { this.tracker.trackedExpectations.remove(id) } @@ -495,7 +508,7 @@ export class EvaluationRunner { } private async _evaluateAllTrackedPackageContainers(): Promise { for (const trackedPackageContainer of this.tracker.trackedPackageContainers.list()) { - const startTime = Date.now() + const timer = startTimer() try { let badStatus = false @@ -708,9 +721,7 @@ export class EvaluationRunner { } ) } - this.logger.debug( - `trackedPackageContainer ${trackedPackageContainer.id}, took ${Date.now() - startTime} ms` - ) + this.logger.debug(`trackedPackageContainer ${trackedPackageContainer.id}, took ${timer.get()} ms`) } } } diff --git a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/fileCopyProxy.ts b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/fileCopyProxy.ts index 3fc6c93e..e414f936 100644 --- a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/fileCopyProxy.ts +++ b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/fileCopyProxy.ts @@ -32,6 +32,7 @@ import { import { doFileCopyExpectation, isFileFulfilled, isFileReadyToStartWorkingOn } from './lib/file' import { getSourceHTTPHandle } from './lib/quantel' import { FFMpegProcess, spawnFFMpeg } from './lib/ffmpeg' +import { startTimer } from '@sofie-package-manager/api' /** * Copies a file from one of the sources and into the target PackageContainer. @@ -90,7 +91,7 @@ export const FileCopyProxy: ExpectationWindowsHandler = { const sourceHandle = lookupSource.handle const targetHandle = lookupTarget.handle - const startTime = Date.now() + const timer = startTimer() if ( lookupSource.accessor.type === Accessor.AccessType.QUANTEL && @@ -142,7 +143,7 @@ export const FileCopyProxy: ExpectationWindowsHandler = { await targetHandle.finalizePackage(fileOperation) await targetHandle.updateMetadata(actualSourceUVersion) - const duration = Date.now() - startTime + const duration = timer.get() wip._reportComplete( actualSourceVersionHash, { diff --git a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/jsonDataCopy.ts b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/jsonDataCopy.ts index 986a9597..c42e0681 100644 --- a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/jsonDataCopy.ts +++ b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/jsonDataCopy.ts @@ -21,6 +21,7 @@ import { import { IWorkInProgress, WorkInProgress } from '../../../lib/workInProgress' import { checkWorkerHasAccessToPackageContainersOnPackage, lookupAccessorHandles, LookupPackageContainer } from './lib' import { PackageReadStream, PutPackageHandler } from '../../../accessorHandlers/genericHandle' +import { startTimer } from '@sofie-package-manager/api' /** * Copies a file from one of the sources and into the target PackageContainer @@ -111,7 +112,7 @@ export const JsonDataCopy: ExpectationWindowsHandler = { if (!isJsonDataCopy(exp)) throw new Error(`Wrong exp.type: "${exp.type}"`) // Copies the file from Source to Target - const startTime = Date.now() + const timer = startTimer() const lookupSource = await lookupCopySources(worker, exp) if (!lookupSource.ready) throw new Error(`Can't start working due to source: ${lookupSource.reason.tech}`) @@ -180,7 +181,7 @@ export const JsonDataCopy: ExpectationWindowsHandler = { await targetHandle.finalizePackage(fileOperation) // await targetHandle.updateMetadata() - const duration = Date.now() - startTime + const duration = timer.get() workInProgress._reportComplete( actualSourceVersionHash, { diff --git a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/lib/file.ts b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/lib/file.ts index e869c233..32c128b6 100644 --- a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/lib/file.ts +++ b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/lib/file.ts @@ -24,6 +24,7 @@ import { CancelablePromise } from '../../../../lib/cancelablePromise' import { PackageReadStream, PutPackageHandler } from '../../../../accessorHandlers/genericHandle' import { diff } from 'deep-diff' import { quantelFileflowCopy } from '../../lib/quantelFileflow' +import { startTimer } from '@sofie-package-manager/api' export async function isFileReadyToStartWorkingOn( worker: GenericWorker, @@ -136,7 +137,7 @@ export async function doFileCopyExpectation( if (!lookupSource.ready) throw new Error(`Can't start working due to source: ${lookupSource.reason.tech}`) if (!lookupTarget.ready) throw new Error(`Can't start working due to target: ${lookupTarget.reason.tech}`) - const startTime = Date.now() + const timer = startTimer() const actualSourceVersion = await lookupSource.handle.getPackageActualVersion() const actualSourceVersionHash = hashObj(actualSourceVersion) @@ -197,7 +198,7 @@ export async function doFileCopyExpectation( await targetHandle.finalizePackage(fileOperation) await targetHandle.updateMetadata(actualSourceUVersion) - const duration = Date.now() - startTime + const duration = timer.get() workInProgress._reportComplete( actualSourceVersionHash, { @@ -295,7 +296,7 @@ export async function doFileCopyExpectation( await targetHandle.finalizePackage(fileOperation) await targetHandle.updateMetadata(actualSourceUVersion) - const duration = Date.now() - startTime + const duration = timer.get() workInProgress._reportComplete( actualSourceVersionHash, { @@ -390,7 +391,7 @@ export async function doFileCopyExpectation( await targetHandle.finalizePackage(fileOperation) await targetHandle.updateMetadata(actualSourceUVersion) - const duration = Date.now() - startTime + const duration = timer.get() workInProgress._reportComplete( actualSourceVersionHash, { diff --git a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/mediaFilePreview.ts b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/mediaFilePreview.ts index e4f39c0e..c93921ef 100644 --- a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/mediaFilePreview.ts +++ b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/mediaFilePreview.ts @@ -28,6 +28,7 @@ import { } from './lib' import { FFMpegProcess, spawnFFMpeg } from './lib/ffmpeg' import { WindowsWorker } from '../windowsWorker' +import { startTimer } from '@sofie-package-manager/api' /** * Generates a low-res preview video of a source video file, and stores the resulting file into the target PackageContainer @@ -142,7 +143,7 @@ export const MediaFilePreview: ExpectationWindowsHandler = { if (!isMediaFilePreview(exp)) throw new Error(`Wrong exp.type: "${exp.type}"`) // Copies the file from Source to Target - const startTime = Date.now() + const timer = startTimer() const lookupSource = await lookupPreviewSources(worker, exp) if (!lookupSource.ready) throw new Error(`Can't start working due to source: ${lookupSource.reason.tech}`) @@ -235,7 +236,7 @@ export const MediaFilePreview: ExpectationWindowsHandler = { await targetHandle.finalizePackage(fileOperation) await targetHandle.updateMetadata(metadata) - const duration = Date.now() - startTime + const duration = timer.get() workInProgress._reportComplete( actualSourceVersionHash, { diff --git a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/mediaFileThumbnail.ts b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/mediaFileThumbnail.ts index 56d758e8..bc784928 100644 --- a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/mediaFileThumbnail.ts +++ b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/mediaFileThumbnail.ts @@ -29,6 +29,7 @@ import { } from './lib' import { FFMpegProcess, spawnFFMpeg } from './lib/ffmpeg' import { WindowsWorker } from '../windowsWorker' +import { startTimer } from '@sofie-package-manager/api' /** * Generates a thumbnail image from a source video file, and stores the resulting file into the target PackageContainer @@ -139,7 +140,7 @@ export const MediaFileThumbnail: ExpectationWindowsHandler = { if (!isMediaFileThumbnail(exp)) throw new Error(`Wrong exp.type: "${exp.type}"`) // Create a thumbnail from the source media file - const startTime = Date.now() + const timer = startTimer() const lookupSource = await lookupThumbnailSources(worker, exp) if (!lookupSource.ready) throw new Error(`Can't start working due to source: ${lookupSource.reason.tech}`) @@ -236,7 +237,7 @@ export const MediaFileThumbnail: ExpectationWindowsHandler = { await targetHandle.finalizePackage(fileOperation) await targetHandle.updateMetadata(metadata) - const duration = Date.now() - startTime + const duration = timer.get() workInProgress._reportComplete( sourceVersionHash, { diff --git a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/packageDeepScan.ts b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/packageDeepScan.ts index 818fe4ed..8623b1e7 100644 --- a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/packageDeepScan.ts +++ b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/packageDeepScan.ts @@ -26,6 +26,7 @@ import { scanWithFFProbe, } from './lib/scan' import { WindowsWorker } from '../windowsWorker' +import { startTimer } from '@sofie-package-manager/api' /** * Performs a "deep scan" of the source package and saves the result file into the target PackageContainer (a Sofie Core collection) @@ -126,7 +127,7 @@ export const PackageDeepScan: ExpectationWindowsHandler = { workOnExpectation: async (exp: Expectation.Any, worker: GenericWorker): Promise => { if (!isPackageDeepScan(exp)) throw new Error(`Wrong exp.type: "${exp.type}"`) // Scan the source media file and upload the results to Core - const startTime = Date.now() + const timer = startTimer() const lookupSource = await lookupDeepScanSources(worker, exp) if (!lookupSource.ready) throw new Error(`Can't start working due to source: ${lookupSource.reason.tech}`) @@ -215,7 +216,7 @@ export const PackageDeepScan: ExpectationWindowsHandler = { await targetHandle.finalizePackage(scanOperation) - const duration = Date.now() - startTime + const duration = timer.get() workInProgress._reportComplete( sourceVersionHash, { diff --git a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/packageLoudnessScan.ts b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/packageLoudnessScan.ts index 63662598..90e5962c 100644 --- a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/packageLoudnessScan.ts +++ b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/packageLoudnessScan.ts @@ -25,6 +25,7 @@ import { } from './lib/scan' import { WindowsWorker } from '../windowsWorker' import { LoudnessScanResult, PackageInfoType } from './lib/coreApi' +import { startTimer } from '@sofie-package-manager/api' /** * Performs a "deep scan" of the source package and saves the result file into the target PackageContainer (a Sofie Core collection) @@ -125,7 +126,7 @@ export const PackageLoudnessScan: ExpectationWindowsHandler = { workOnExpectation: async (exp: Expectation.Any, worker: GenericWorker): Promise => { if (!isPackageLoudnessScan(exp)) throw new Error(`Wrong exp.type: "${exp.type}"`) // Scan the source media file and upload the results to Core - const startTime = Date.now() + const timer = startTimer() const lookupSource = await lookupLoudnessSources(worker, exp) if (!lookupSource.ready) throw new Error(`Can't start working due to source: ${lookupSource.reason.tech}`) @@ -190,7 +191,7 @@ export const PackageLoudnessScan: ExpectationWindowsHandler = { ) await targetHandle.finalizePackage(scanOperation) - const duration = Date.now() - startTime + const duration = timer.get() workInProgress._reportComplete( sourceVersionHash, { diff --git a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/packageScan.ts b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/packageScan.ts index 5c76ac81..b6fffc98 100644 --- a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/packageScan.ts +++ b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/packageScan.ts @@ -19,6 +19,7 @@ import { CancelablePromise } from '../../../lib/cancelablePromise' import { isAnFFMpegSupportedSourceAccessor, isAnFFMpegSupportedSourceAccessorHandle, scanWithFFProbe } from './lib/scan' import { WindowsWorker } from '../windowsWorker' import { PackageInfoType } from './lib/coreApi' +import { startTimer } from '@sofie-package-manager/api' /** * Scans the source package and saves the result file into the target PackageContainer (a Sofie Core collection) @@ -118,7 +119,7 @@ export const PackageScan: ExpectationWindowsHandler = { workOnExpectation: async (exp: Expectation.Any, worker: GenericWorker): Promise => { if (!isPackageScan(exp)) throw new Error(`Wrong exp.type: "${exp.type}"`) // Scan the source package and upload the results to Core - const startTime = Date.now() + const timer = startTimer() const lookupSource = await lookupScanSources(worker, exp) if (!lookupSource.ready) throw new Error(`Can't start working due to source: ${lookupSource.reason.tech}`) @@ -174,7 +175,7 @@ export const PackageScan: ExpectationWindowsHandler = { await targetHandle.finalizePackage(scanOperation) - const duration = Date.now() - startTime + const duration = timer.get() workInProgress._reportComplete( sourceVersionHash, { diff --git a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/quantelClipCopy.ts b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/quantelClipCopy.ts index 0ca3f601..60888569 100644 --- a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/quantelClipCopy.ts +++ b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/quantelClipCopy.ts @@ -15,6 +15,7 @@ import { import { isQuantelClipAccessorHandle } from '../../../accessorHandlers/accessor' import { IWorkInProgress, WorkInProgress } from '../../../lib/workInProgress' import { checkWorkerHasAccessToPackageContainersOnPackage, lookupAccessorHandles, LookupPackageContainer } from './lib' +import { startTimer } from '@sofie-package-manager/api' export const QuantelClipCopy: ExpectationWindowsHandler = { doYouSupportExpectation(exp: Expectation.Any, genericWorker: GenericWorker): ReturnTypeDoYouSupportExpectation { @@ -134,7 +135,7 @@ export const QuantelClipCopy: ExpectationWindowsHandler = { if (!isQuantelClipCopy(exp)) throw new Error(`Wrong exp.type: "${exp.type}"`) // Copies the clip from Source to Target - const startTime = Date.now() + const timer = startTimer() const lookupSource = await lookupCopySources(worker, exp) if (!lookupSource.ready) throw new Error(`Can't start working due to source: ${lookupSource.reason.tech}`) @@ -236,7 +237,7 @@ export const QuantelClipCopy: ExpectationWindowsHandler = { await targetHandle.finalizePackage(quantelOperation) await targetHandle.updateMetadata(actualSourceUVersion) - const duration = Date.now() - startTime + const duration = timer.get() workInProgress._reportComplete( actualSourceVersionHash, { diff --git a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/quantelClipPreview.ts b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/quantelClipPreview.ts index 821edc17..dd6221e0 100644 --- a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/quantelClipPreview.ts +++ b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/quantelClipPreview.ts @@ -28,6 +28,7 @@ import { import { getSourceHTTPHandle } from './lib/quantel' import { FFMpegProcess, spawnFFMpeg } from './lib/ffmpeg' import { WindowsWorker } from '../windowsWorker' +import { startTimer } from '@sofie-package-manager/api' export const QuantelClipPreview: ExpectationWindowsHandler = { doYouSupportExpectation( @@ -151,7 +152,7 @@ export const QuantelClipPreview: ExpectationWindowsHandler = { if (!isQuantelClipPreview(exp)) throw new Error(`Wrong exp.type: "${exp.type}"`) // Copies the file from Source to Target - const startTime = Date.now() + const timer = startTimer() const lookupSource = await lookupPreviewSources(worker, exp) if (!lookupSource.ready) throw new Error(`Can't start working due to source: ${lookupSource.reason.tech}`) @@ -222,7 +223,7 @@ export const QuantelClipPreview: ExpectationWindowsHandler = { await targetHandle.finalizePackage(quantelOperation) await targetHandle.updateMetadata(metadata) - const duration = Date.now() - startTime + const duration = timer.get() workInProgress._reportComplete( actualSourceVersionHash, { diff --git a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/quantelClipThumbnail.ts b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/quantelClipThumbnail.ts index 8efeacae..df9f1434 100644 --- a/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/quantelClipThumbnail.ts +++ b/shared/packages/worker/src/worker/workers/windowsWorker/expectationHandlers/quantelClipThumbnail.ts @@ -25,6 +25,7 @@ import { checkWorkerHasAccessToPackageContainersOnPackage, lookupAccessorHandles import { PackageReadStream, PutPackageHandler } from '../../../accessorHandlers/genericHandle' import { WindowsWorker } from '../windowsWorker' import { getSourceHTTPHandle, QuantelClipMetadata } from './lib/quantel' +import { startTimer } from '@sofie-package-manager/api' /** * Generates a thumbnail image from a source quantel clip, and stores the resulting file into the target PackageContainer @@ -148,7 +149,7 @@ export const QuantelThumbnail: ExpectationWindowsHandler = { if (!isQuantelClipThumbnail(exp)) throw new Error(`Wrong exp.type: "${exp.type}"`) // Fetch the Thumbnail from the Quantel HTTP-transformer and put it on the target - const startTime = Date.now() + const timer = startTimer() const lookupSource = await lookupThumbnailSources(worker, exp) if (!lookupSource.ready) throw new Error(`Can't start working due to source: ${lookupSource.reason.tech}`) @@ -222,7 +223,7 @@ export const QuantelThumbnail: ExpectationWindowsHandler = { await lookupTarget.handle.finalizePackage(quantelOperation) await lookupTarget.handle.updateMetadata(targetMetadata) - const duration = Date.now() - startTime + const duration = timer.get() workInProgress._reportComplete( targetMetadata.sourceVersionHash, { diff --git a/tests/internal-tests/src/__tests__/lib/lib.ts b/tests/internal-tests/src/__tests__/lib/lib.ts index 08dcfd7e..da347abc 100644 --- a/tests/internal-tests/src/__tests__/lib/lib.ts +++ b/tests/internal-tests/src/__tests__/lib/lib.ts @@ -1,3 +1,5 @@ +import { startTimer } from '@sofie-package-manager/api' + export function waitTime(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)) } @@ -7,14 +9,14 @@ export function waitTime(ms: number): Promise { * Useful in unit-tests as a way to wait until a predicate is fulfilled. */ export async function waitUntil(expectFcn: () => void, maxWaitTime: number): Promise { - const startTime = Date.now() + const timer = startTimer() while (true) { await waitTime(100) try { expectFcn() return } catch (err) { - let waitedTime = Date.now() - startTime + let waitedTime = timer.get() if (waitedTime > maxWaitTime) { console.log(`waitUntil: waited for ${waitedTime} ms, giving up (maxWaitTime: ${maxWaitTime}).`) throw err