From 7763752bdec9669e02939b912fb319f450126d9c Mon Sep 17 00:00:00 2001 From: ChaosEngine Date: Sat, 4 Nov 2023 18:06:13 +0100 Subject: [PATCH] test refactoring and speedup --- test/InkBall.Tests/IntegrationTests.cs | 2 +- test/InkBall.Tests/SignalRTests.cs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/test/InkBall.Tests/IntegrationTests.cs b/test/InkBall.Tests/IntegrationTests.cs index d392dfc7..5b5d7cb7 100644 --- a/test/InkBall.Tests/IntegrationTests.cs +++ b/test/InkBall.Tests/IntegrationTests.cs @@ -22,7 +22,7 @@ public static class PostRequestHelper { public static string ExtractAntiForgeryToken(string htmlResponseText) { - if (htmlResponseText == null) throw new ArgumentNullException("htmlResponseText"); + ArgumentNullException.ThrowIfNull(htmlResponseText); Match match = Regex.Match(htmlResponseText, @"\"); return match.Success ? match.Groups[1].Captures[0].Value : null; diff --git a/test/InkBall.Tests/SignalRTests.cs b/test/InkBall.Tests/SignalRTests.cs index 0c4cb60c..8f34c6a2 100644 --- a/test/InkBall.Tests/SignalRTests.cs +++ b/test/InkBall.Tests/SignalRTests.cs @@ -394,7 +394,7 @@ await hub_P2.ClientToServerPoint(new InkBallPointViewModel Status = InkBallPoint.StatusEnum.POINT_FREE_BLUE, }); } - await Task.Delay(TimeSpan.FromSeconds(4));//wait before next action + await Task.Delay(TimeSpan.FromMicroseconds(200));//wait before next action var pt = await hub_P1.ClientToServerPoint(new InkBallPointViewModel { iGameId = 1, @@ -405,7 +405,8 @@ await hub_P2.ClientToServerPoint(new InkBallPointViewModel }); Assert.NotNull(pt.TimeStamp); //verify last action timestamp it not from previous action - Assert.Equal(DateTime.UtcNow, pt.TimeStamp.Value, TimeSpan.FromSeconds(2)); + var utc_now = DateTime.UtcNow; + Assert.Equal(utc_now, pt.TimeStamp.Value, TimeSpan.FromSeconds(1)); pt = await hub_P2.ClientToServerPoint(new InkBallPointViewModel { iGameId = 1, @@ -417,7 +418,7 @@ await hub_P2.ClientToServerPoint(new InkBallPointViewModel Assert.NotNull(pt.TimeStamp); //Act - await Task.Delay(TimeSpan.FromSeconds(4));//wait before next action + await Task.Delay(TimeSpan.FromMilliseconds(200));//wait before next action var dto = await hub_P1.ClientToServerPath(new InkBallPathViewModel { iGameId = 1, @@ -428,7 +429,8 @@ await hub_P2.ClientToServerPoint(new InkBallPointViewModel //Assert Assert.IsType(dto); Assert.NotNull(((InkBallPathViewModel)dto).TimeStamp); - Assert.Equal(DateTime.UtcNow, ((InkBallPathViewModel)dto).TimeStamp.Value, TimeSpan.FromSeconds(2)); + utc_now = DateTime.UtcNow; + Assert.Equal(utc_now, ((InkBallPathViewModel)dto).TimeStamp.Value, TimeSpan.FromSeconds(1)); } }