public IEnumerator MetricsSubmission_ShouldTry3TimesOn503AndDropSummedEventsOnMaximumNumberOfEvents_DataWasDeleted() { const int expectedNumberOfEventsAfterFailure = 1; // unique events and we have enough place for session event so also session event var requestHandler = new BacktraceHttpClientMock() { StatusCode = 503 }; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.OverrideHttpClient(requestHandler); for (int i = 0; i < backtraceMetrics.MaximumSummedEvents; i++) { backtraceMetrics.AddSummedEvent(MetricsEventName); } backtraceMetrics.AddUniqueEvent(UniqueAttributeName); backtraceMetrics.Send(); for (int i = 0; i < BacktraceMetrics.MaxNumberOfAttempts; i++) { yield return(new WaitForSeconds(1)); // immidiately run next update var time = BacktraceMetrics.MaxTimeBetweenRequests + (BacktraceMetrics.MaxTimeBetweenRequests * i) + i + 1; backtraceMetrics.Tick(time); } yield return(new WaitForSeconds(1)); Assert.AreEqual(expectedNumberOfEventsAfterFailure, backtraceMetrics.Count()); Assert.AreEqual(BacktraceMetrics.MaxNumberOfAttempts * 2, requestHandler.NumberOfRequests); }
public IEnumerator MetricsSubmission_ShouldTry3TimesOn502BeforeDroppingEvents_DataWasntSendToBacktrace() { const int expectedNumberOfEventsAfterFailure = 2; var requestHandler = new BacktraceHttpClientMock() { StatusCode = 502 }; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.OverrideHttpClient(requestHandler); backtraceMetrics.AddSummedEvent(MetricsEventName); backtraceMetrics.AddUniqueEvent(UniqueAttributeName); backtraceMetrics.Send(); for (int i = 0; i < BacktraceMetrics.MaxNumberOfAttempts; i++) { yield return(new WaitForSeconds(1)); // immidiately run next update var time = BacktraceMetrics.MaxTimeBetweenRequests + (BacktraceMetrics.MaxTimeBetweenRequests * i) + i + 1; backtraceMetrics.Tick(time); } yield return(new WaitForSeconds(1)); Assert.AreEqual(BacktraceMetrics.MaxNumberOfAttempts * 2, requestHandler.NumberOfRequests); Assert.AreEqual(backtraceMetrics.Count(), expectedNumberOfEventsAfterFailure); }
public void BacktraceMetricsUniqueEvents_ShoulOverrideDefaultSubmissionUrl_SendEventToValidUrl() { var expectedSubmissionUrl = string.Format("{0}/unique-events/unit-test/submit?token={1}&universe={2}", _defaultSubmissionUrl, _token, _universeName); var jsonString = string.Empty; var submissionUrl = string.Empty; var requestHandler = new BacktraceHttpClientMock() { OnInvoke = (string url, BacktraceJObject json) => { jsonString = json.ToJson(); submissionUrl = url; } }; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl) { UniqueEventsSubmissionUrl = expectedSubmissionUrl }; backtraceMetrics.OverrideHttpClient(requestHandler); backtraceMetrics.AddUniqueEvent(UniqueAttributeName); backtraceMetrics.Send(); Assert.IsNotEmpty(jsonString); Assert.AreEqual(expectedSubmissionUrl, submissionUrl); Assert.IsEmpty(backtraceMetrics.SummedEvents); }
public void BacktraceMetrics_ShouldntTriggerUploadWhenDataIsNotAvailable_DataWasntSendToBacktrace() { var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); var requestHandler = new BacktraceHttpClientMock(); backtraceMetrics.OverrideHttpClient(requestHandler); backtraceMetrics.Send(); Assert.IsFalse(requestHandler.Called); }
public void BacktraceMetrics_ShouldTryOnlyOnceOnHttpFailure_DataWasntSendToBacktrace() { var requestHandler = new BacktraceHttpClientMock() { IsHttpError = true }; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.OverrideHttpClient(requestHandler); backtraceMetrics.AddSummedEvent(MetricsEventName); backtraceMetrics.AddUniqueEvent(UniqueAttributeName); backtraceMetrics.Send(); Assert.AreEqual(2, requestHandler.NumberOfRequests); }
public void BacktraceMetrics_ShouldTriggerUploadProcessOnSendMethodWithOnlyUniqueEvent_DataWasSendToTheService() { var jsonString = string.Empty; var submissionUrl = string.Empty; var requestHandler = new BacktraceHttpClientMock() { OnInvoke = (string url, BacktraceJObject json) => { jsonString = json.ToJson(); submissionUrl = url; } }; var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.OverrideHttpClient(requestHandler); backtraceMetrics.AddUniqueEvent(UniqueAttributeName); backtraceMetrics.Send(); Assert.IsNotEmpty(jsonString); Assert.AreEqual(submissionUrl, _expectedUniqueEventsSubmissionUrl); Assert.IsEmpty(backtraceMetrics.SummedEvents); }