From 4bf5a3629ffd4074ea6d944f419862af457e9767 Mon Sep 17 00:00:00 2001 From: Bastien Caudan <1331991+bcaudan@users.noreply.github.com> Date: Tue, 25 Apr 2023 09:19:29 +0200 Subject: [PATCH] Remove remaining feature flag test warning noise (#2185) --- .../rum-core/src/domain/contexts/featureFlagContext.spec.ts | 1 + packages/rum-core/src/domain/contexts/featureFlagContext.ts | 5 ++++- packages/rum-core/test/testSetupBuilder.ts | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts b/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts index 0d84749127..364f121f1c 100644 --- a/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts +++ b/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts @@ -33,6 +33,7 @@ describe('featureFlagContexts', () => { }) afterEach(() => { + featureFlagContexts.stop() resetExperimentalFeatures() setupBuilder.cleanup() }) diff --git a/packages/rum-core/src/domain/contexts/featureFlagContext.ts b/packages/rum-core/src/domain/contexts/featureFlagContext.ts index dfc18a486f..73c7f4c38d 100644 --- a/packages/rum-core/src/domain/contexts/featureFlagContext.ts +++ b/packages/rum-core/src/domain/contexts/featureFlagContext.ts @@ -23,6 +23,7 @@ export interface FeatureFlagContexts { findFeatureFlagEvaluations: (startTime?: RelativeTime) => FeatureFlagContext | undefined getFeatureFlagBytesCount: () => number addFeatureFlagEvaluation: (key: string, value: ContextValue) => void + stop: () => void } /** @@ -42,6 +43,7 @@ export function startFeatureFlagContexts( findFeatureFlagEvaluations: () => undefined, getFeatureFlagBytesCount: () => 0, addFeatureFlagEvaluation: noop, + stop: noop, } } @@ -60,7 +62,7 @@ export function startFeatureFlagContexts( // Throttle the bytes computation to minimize the impact on performance. // Especially useful if the user call addFeatureFlagEvaluation API synchronously multiple times in a row - const { throttled: computeBytesCountThrottled } = throttle((context: Context) => { + const { throttled: computeBytesCountThrottled, cancel: cancelPendingComputation } = throttle((context: Context) => { bytesCountCache = computeBytesCountImpl(jsonStringify(context)!) if (!alreadyWarned) { alreadyWarned = warnIfCustomerDataLimitReached(bytesCountCache, CustomerDataType.FeatureFlag) @@ -84,5 +86,6 @@ export function startFeatureFlagContexts( computeBytesCountThrottled(currentContext) } }, + stop: cancelPendingComputation, } } diff --git a/packages/rum-core/test/testSetupBuilder.ts b/packages/rum-core/test/testSetupBuilder.ts index c8ef83d379..b9c01253ef 100644 --- a/packages/rum-core/test/testSetupBuilder.ts +++ b/packages/rum-core/test/testSetupBuilder.ts @@ -88,6 +88,7 @@ export function setup(): TestSetupBuilder { let featureFlagContexts: FeatureFlagContexts = { findFeatureFlagEvaluations: () => undefined, addFeatureFlagEvaluation: noop, + stop: noop, getFeatureFlagBytesCount: () => 0, } let actionContexts: ActionContexts = {