public void StopsTransmissionSendingAndBuffering() { var transmitter = new StubTransmitter(); var applicationLifecycle = new StubApplicationLifecycle(); var policy = new ApplicationLifecycleTransmissionPolicy(applicationLifecycle); policy.Initialize(transmitter); applicationLifecycle.OnStopping(ApplicationStoppingEventArgs.Empty); Assert.Equal(0, policy.MaxSenderCapacity); Assert.Equal(0, policy.MaxBufferCapacity); }
public void EventHandlerIsNotAssignedInConstructorToPreventRaceConditionWithInitialize() { var applicationLifecycle = new StubApplicationLifecycle(); var policy = new ApplicationLifecycleTransmissionPolicy(applicationLifecycle); bool asyncMethodInvoked = false; Func<Func<Task>, Task> asyncMethodRunner = asyncMethod => { asyncMethodInvoked = true; return asyncMethod(); }; applicationLifecycle.OnStopping(new ApplicationStoppingEventArgs(asyncMethodRunner)); Assert.False(asyncMethodInvoked); }
public void PreventsOperatingSystemFromSuspendingAsynchronousOperations() { var applicationLifecycle = new StubApplicationLifecycle(); var buffer = new TelemetryBuffer(new StubTelemetrySerializer(), applicationLifecycle); buffer.Process(new StubTelemetry()); bool deferralAcquired = false; Func<Func<Task>, Task> asyncTaskRunner = asyncMethod => { deferralAcquired = true; return asyncMethod(); }; applicationLifecycle.OnStopping(new ApplicationStoppingEventArgs(asyncTaskRunner)); Assert.True(deferralAcquired); }
public void FlushesBufferToPreventLossOfTelemetry() { var applicationLifecycle = new StubApplicationLifecycle(); var telemetrySerialized = new ManualResetEventSlim(); var serializer = new StubTelemetrySerializer(); serializer.OnSerialize = telemetry => { telemetrySerialized.Set(); }; var buffer = new TelemetryBuffer(serializer, applicationLifecycle); buffer.Process(new StubTelemetry()); applicationLifecycle.OnStopping(ApplicationStoppingEventArgs.Empty); Assert.True(telemetrySerialized.Wait(50)); }