From 01d66bbf93d09323dcd55aec9534dbd7b3117d8b Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 30 Jan 2015 14:40:01 -0800 Subject: [PATCH] [Telemetry] Add test case for lossless subscription Add a test case for subscriptions which should be handled losslessly (that is, which should notify subscribers once per data event, not once per execution cycle.) This test case reflects the underlying cause for WTD-784. --- .../test/TelemetrySubscriptionSpec.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/platform/telemetry/test/TelemetrySubscriptionSpec.js b/platform/telemetry/test/TelemetrySubscriptionSpec.js index 3a02632e47..8aca781f40 100644 --- a/platform/telemetry/test/TelemetrySubscriptionSpec.js +++ b/platform/telemetry/test/TelemetrySubscriptionSpec.js @@ -120,6 +120,47 @@ define( // Should have no objects expect(subscription.getTelemetryObjects()).toEqual([]); }); + + // This test case corresponds to plot usage of + // telemetrySubscription, where failure to callback + // once-per-update results in loss of data, WTD-784 + it("fires one event per update if requested", function () { + var i, domains = [], ranges = [], lastCall; + + // Clear out the subscription from beforeEach + subscription.unsubscribe(); + // Create a subscription which does not drop events + subscription = new TelemetrySubscription( + mockQ, + mockTimeout, + mockDomainObject, + mockCallback, + true // Don't drop updates! + ); + + // Snapshot getDomainValue, getRangeValue at time of callback + mockCallback.andCallFake(function () { + domains.push(subscription.getDomainValue(mockDomainObject)); + ranges.push(subscription.getRangeValue(mockDomainObject)); + }); + + // Send 100 updates + for (i = 0; i < 100; i += 1) { + // Return different values to verify later + mockSeries.getDomainValue.andReturn(i); + mockSeries.getRangeValue.andReturn(i * 2); + mockTelemetry.subscribe.mostRecentCall.args[0](mockSeries); + } + + // Fire all timeouts that get scheduled + while (mockTimeout.mostRecentCall !== lastCall) { + lastCall = mockTimeout.mostRecentCall; + lastCall.args[0](); + } + + // Should have only triggered the + expect(mockCallback.calls.length).toEqual(100); + }); }); } ); \ No newline at end of file