a test timeout ...

vnext
Paul Schneider 6 years ago
parent af3973af65
commit 046429dde2
2 changed files with 48 additions and 11 deletions

@ -27,17 +27,21 @@ namespace test
[Fact]
public void SendEMailSynchrone()
{
output.WriteLine("SendEMailSynchrone ...");
EmailSentViewModel mailSentInfo = _serverFixture._mailSender.SendEmailAsync
(_serverFixture._siteSetup.Owner.Name, _serverFixture._siteSetup.Owner.EMail, $"monthly email", "test boby monthly email").Result;
if (mailSentInfo==null)
_serverFixture._logger.LogError("No info on sending");
else if (!mailSentInfo.Sent)
_serverFixture._logger.LogError($"{mailSentInfo.ErrorMessage}");
else
_serverFixture._logger.LogInformation($"mailId:{mailSentInfo.MessageId} \nto:{_serverFixture._siteSetup.Owner.Name}");
Assert.NotNull(mailSentInfo);
output.WriteLine($">>done with {mailSentInfo.EMail} {mailSentInfo.Sent} {mailSentInfo.MessageId} {mailSentInfo.ErrorMessage}");
AssertAsync.CompletesIn(2, () =>
{
output.WriteLine("SendEMailSynchrone ...");
EmailSentViewModel mailSentInfo = _serverFixture._mailSender.SendEmailAsync
(_serverFixture._siteSetup.Owner.Name, _serverFixture._siteSetup.Owner.EMail, $"monthly email", "test boby monthly email").Result;
if (mailSentInfo==null)
_serverFixture._logger.LogError("No info on sending");
else if (!mailSentInfo.Sent)
_serverFixture._logger.LogError($"{mailSentInfo.ErrorMessage}");
else
_serverFixture._logger.LogInformation($"mailId:{mailSentInfo.MessageId} \nto:{_serverFixture._siteSetup.Owner.Name}");
Assert.NotNull(mailSentInfo);
output.WriteLine($">>done with {mailSentInfo.EMail} {mailSentInfo.Sent} {mailSentInfo.MessageId} {mailSentInfo.ErrorMessage}");
});
}
}
}

@ -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.");
}
}
}
}
Loading…