Skip to content

Commit

Permalink
Adding context info on tests that might be failing because of read ti…
Browse files Browse the repository at this point in the history
…meouts to confirm if that's the case.

Refactoring.

Refactoring som more. Increasing the read timeout.

Refactoring more.
  • Loading branch information
amanda-tarafa committed Oct 12, 2018
1 parent a3b2645 commit c511a46
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ public async Task LogsException()

Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);

var errorEvent = s_polling.GetEvents(_testId, 1).Single();

var errorEvent = ErrorEventEntryVerifiers.VerifySingle(s_polling, _testId);
ErrorEventEntryVerifiers.VerifyFullErrorEventLogged(errorEvent, _testId, nameof(ErrorReportingController.ThrowsException));

var content = await contentTask;
Expand All @@ -90,8 +89,7 @@ public async Task LogsMultipleExceptions()
response = await requestTask4;
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);

var errorEvents = s_polling.GetEvents(_testId, 4);
Assert.Equal(4, errorEvents.Count());
var errorEvents = ErrorEventEntryVerifiers.VerifyMany(s_polling, _testId, 4);

var exceptionEvents = errorEvents
.Where(e => e.Message.Contains(nameof(ErrorReportingController.ThrowsException)));
Expand All @@ -114,8 +112,7 @@ public async Task LogsThrownInHttpMessageHandler()

Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);

var errorEvent = s_polling.GetEvents(_testId, 1).Single();

var errorEvent = ErrorEventEntryVerifiers.VerifySingle(s_polling, _testId);
ErrorEventEntryVerifiers.VerifyFullErrorEventLogged(errorEvent, _testId, "SendAsync");
}

Expand All @@ -126,7 +123,7 @@ public async Task ManualLog_GoogleLogger()

Assert.Equal(HttpStatusCode.OK, response.StatusCode);

var errorEvent = s_polling.GetEvents(_testId, 1).Single();
var errorEvent = ErrorEventEntryVerifiers.VerifySingle(s_polling, _testId);
ErrorEventEntryVerifiers.VerifyErrorEventLogged(errorEvent, _testId, nameof(ErrorReportingController.ThrowCatchWithGoogleLogger));
}

Expand All @@ -137,7 +134,7 @@ public async Task ManualLog_GoogleWebApiLogger()

Assert.Equal(HttpStatusCode.OK, response.StatusCode);

var errorEvent = s_polling.GetEvents(_testId, 1).Single();
var errorEvent = ErrorEventEntryVerifiers.VerifySingle(s_polling, _testId);
ErrorEventEntryVerifiers.VerifyFullErrorEventLogged(errorEvent, _testId, nameof(ErrorReportingController.ThrowCatchWithGoogleWebApiLogger));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public async Task LogsException()

Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);

var errorEvent = s_polling.GetEvents(_testId, 1).Single();

var errorEvent = ErrorEventEntryVerifiers.VerifySingle(s_polling, _testId);
ErrorEventEntryVerifiers.VerifyFullErrorEventLogged(
errorEvent, _testId, nameof(ErrorReportingController.ThrowsException));
}
Expand All @@ -76,7 +75,7 @@ public async Task ManualLog_GoogleWebApiLogger()

Assert.Equal(HttpStatusCode.OK, response.StatusCode);

var errorEvent = s_polling.GetEvents(_testId, 1).Single();
var errorEvent = ErrorEventEntryVerifiers.VerifySingle(s_polling, _testId);
ErrorEventEntryVerifiers.VerifyFullErrorEventLogged(
errorEvent, _testId, "DoSomething");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private static async Task TestErrorReporting(string testId, HttpClient client)
{
var polling = new ErrorEventEntryPolling();
await Assert.ThrowsAsync<Exception>(() => client.GetAsync($"/ErrorReporting/{nameof(ErrorReportingController.ThrowsException)}/{testId}"));
var errorEvent = polling.GetEvents(testId, 1).Single();
var errorEvent = ErrorEventEntryVerifiers.VerifySingle(polling, testId);
ErrorEventEntryVerifiers.VerifyFullErrorEventLogged(errorEvent, testId, nameof(ErrorReportingController.ThrowsException));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task ManualLog()

Assert.Equal(HttpStatusCode.OK, response.StatusCode);

var errorEvent = s_polling.GetEvents(_testId, 1).Single();
var errorEvent = ErrorEventEntryVerifiers.VerifySingle(s_polling, _testId);
ErrorEventEntryVerifiers.VerifyFullErrorEventLogged(errorEvent, _testId, nameof(ErrorReportingController.ThrowCatchLog));
}

Expand All @@ -74,7 +74,7 @@ public async Task LogsException()
await Assert.ThrowsAsync<Exception>(() =>
_client.GetAsync($"/ErrorReporting/{nameof(ErrorReportingController.ThrowsException)}/{_testId}"));

var errorEvent = s_polling.GetEvents(_testId, 1).Single();
var errorEvent = ErrorEventEntryVerifiers.VerifySingle(s_polling, _testId);
ErrorEventEntryVerifiers.VerifyFullErrorEventLogged(errorEvent, _testId, nameof(ErrorReportingController.ThrowsException));
}

Expand All @@ -90,8 +90,7 @@ public async Task LogsMultipleExceptions()
await Assert.ThrowsAsync<Exception>(() =>
_client.GetAsync($"/ErrorReporting/{nameof(ErrorReportingController.ThrowsException)}/{_testId}"));

var errorEvents = s_polling.GetEvents(_testId, 4);
Assert.Equal(4, errorEvents.Count());
var errorEvents = ErrorEventEntryVerifiers.VerifyMany(s_polling, _testId, 4);

var exceptionEvents = errorEvents.Where(e => e.Message.Contains(nameof(ErrorReportingController.ThrowsException)));
Assert.Equal(3, exceptionEvents.Count());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using Microsoft.AspNetCore.TestHost;
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;
Expand Down Expand Up @@ -71,8 +70,7 @@ public async Task Logs_UnhandledException()
{
await Assert.ThrowsAsync<Exception>(() => _client.GetAsync($"/ErrorLoggingSamples/{nameof(ErrorLoggingSamplesController.ThrowsException)}/{_testId}"));

var errorEvent = s_errorPolling.GetEvents(_testId, 1).Single();

var errorEvent = ErrorEventEntryVerifiers.VerifySingle(s_errorPolling, _testId);
ErrorEventEntryVerifiers.VerifyFullErrorEventLogged(errorEvent, _testId, nameof(ErrorLoggingSamplesController.ThrowsException));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public async Task Logs_UnhandledException()
await Assert.ThrowsAsync<Exception>(()
=> _client.GetAsync($"/ErrorLoggingSamples/{nameof(ErrorLoggingSamplesController.ThrowsException)}/{_testId}"));

var errorEvent = s_polling.GetEvents(_testId, 1).Single();

var errorEvent = ErrorEventEntryVerifiers.VerifySingle(s_polling, _testId);
ErrorEventEntryVerifiers.VerifyFullErrorEventLogged(errorEvent, _testId, nameof(ErrorLoggingSamplesController.ThrowsException));
}

Expand All @@ -76,7 +75,7 @@ public async Task Logs_Explicitly()

Assert.Equal(HttpStatusCode.OK, response.StatusCode);

var errorEvent = s_polling.GetEvents(_testId, 1).Single();
var errorEvent = ErrorEventEntryVerifiers.VerifySingle(s_polling, _testId);

// Verifying with function name ThrowsExceptions because that is the function
// that actually throws the Exception so will be the one included as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal class ErrorEventEntryPolling : BaseEntryPolling<ErrorEvent>
private readonly ProjectName _projectName = new ProjectName(TestEnvironment.GetTestProjectId());

// Give the error reporting events a little extra time to be processed.
internal ErrorEventEntryPolling() : base(TimeSpan.FromSeconds(180), TimeSpan.FromSeconds(30)) { }
internal ErrorEventEntryPolling() : base(TimeSpan.FromSeconds(600), TimeSpan.FromSeconds(30)) { }

/// <summary>
/// Gets error events that contain the passed in testId in the message. Will poll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,38 @@

using Google.Cloud.ClientTesting;
using Google.Cloud.ErrorReporting.V1Beta1;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using Xunit;

namespace Google.Cloud.Diagnostics.Common.IntegrationTests
{
public static class ErrorEventEntryVerifiers
internal static class ErrorEventEntryVerifiers
{
/// <summary>
/// Checks that there's only one event present.
/// Includes a message with context info to help track the possible issue.
/// </summary>
public static ErrorEvent VerifySingle(ErrorEventEntryPolling polling, string contextInfo)
{
var events = polling.GetEvents(contextInfo, 1);
var errorEvent = events.SingleOrDefault();
Assert.True(errorEvent != null, $"No entries found for context {contextInfo}");
return errorEvent;
}

/// <summary>
/// Checks that there are <paramref name="expected"/> events present.
/// Includes a message with context info to help track the possible issue.
/// </summary>
public static IEnumerable<ErrorEvent> VerifyMany(ErrorEventEntryPolling polling, string contextInfo, int expected)
{
var events = polling.GetEvents(contextInfo, expected).ToList();
Assert.True(expected == events.Count, $"Should have found {expected} entries for contest {contextInfo} but found {events.Count}");
return events;
}

/// <summary>
/// Checks that an <see cref="ErrorEvent"/> contains valid data,
/// including HTTP Context data.
Expand Down

0 comments on commit c511a46

Please sign in to comment.