public void DiagnosticPeriodicEventsAreNotSentWhenInBackground() { var mockBackgroundModeManager = new MockBackgroundModeManager(); var config = BasicConfig() .BackgroundModeManager(mockBackgroundModeManager) .Events(Components.SendEvents() .EventSender(_testEventSender) .DiagnosticRecordingIntervalNoMinimum(TimeSpan.FromMilliseconds(50))) .Build(); using (var client = TestUtil.CreateClient(config, BasicUser)) { mockBackgroundModeManager.UpdateBackgroundMode(true); // We will probably still get some periodic events before this mode change is picked // up asynchronously, but we should stop getting them soon. Assertions.AssertEventually(TimeSpan.FromMilliseconds(400), TimeSpan.FromMilliseconds(10), () => !_testEventSender.Calls.TryTake(out _, TimeSpan.FromMilliseconds(100))); mockBackgroundModeManager.UpdateBackgroundMode(false); _testEventSender.RequirePayload(); } }