a test timeout ...

This commit is contained in:
Paul Schneider 2018-07-20 02:48:21 +02:00
commit 262edc499b
2 changed files with 48 additions and 11 deletions

View file

@ -26,6 +26,9 @@ namespace test
[Fact] [Fact]
public void SendEMailSynchrone() public void SendEMailSynchrone()
{
AssertAsync.CompletesIn(2, () =>
{ {
output.WriteLine("SendEMailSynchrone ..."); output.WriteLine("SendEMailSynchrone ...");
EmailSentViewModel mailSentInfo = _serverFixture._mailSender.SendEmailAsync EmailSentViewModel mailSentInfo = _serverFixture._mailSender.SendEmailAsync
@ -38,6 +41,7 @@ namespace test
_serverFixture._logger.LogInformation($"mailId:{mailSentInfo.MessageId} \nto:{_serverFixture._siteSetup.Owner.Name}"); _serverFixture._logger.LogInformation($"mailId:{mailSentInfo.MessageId} \nto:{_serverFixture._siteSetup.Owner.Name}");
Assert.NotNull(mailSentInfo); Assert.NotNull(mailSentInfo);
output.WriteLine($">>done with {mailSentInfo.EMail} {mailSentInfo.Sent} {mailSentInfo.MessageId} {mailSentInfo.ErrorMessage}"); output.WriteLine($">>done with {mailSentInfo.EMail} {mailSentInfo.Sent} {mailSentInfo.MessageId} {mailSentInfo.ErrorMessage}");
});
} }
} }
} }

33
test/src/TestHelpers.cs Normal file
View file

@ -0,0 +1,33 @@
using System;
using System.Threading.Tasks;
namespace test {
public static class AssertAsync {
public static void CompletesIn(int timeout, Action action)
{
var task = Task.Run(action);
var completedInTime = Task.WaitAll(new[] { task }, TimeSpan.FromSeconds(timeout));
if (task.Exception != null)
{
if (task.Exception.InnerExceptions.Count == 1)
{
throw task.Exception.InnerExceptions[0];
}
throw task.Exception;
}
if (!completedInTime)
{
throw new TimeoutException($"Task did not complete in {timeout} seconds.");
}
}
}
}