Fix potential race conditions with user subscription test

This commit is contained in:
Jordan Dominion
2024-10-02 20:28:32 -04:00
parent 330fbdf08a
commit d24abb5920
2 changed files with 16 additions and 4 deletions
@@ -1,4 +1,5 @@
using System;
using System.Threading;
namespace Tgstation.Server.Tests.Live
{
@@ -10,9 +11,12 @@ namespace Tgstation.Server.Tests.Live
public T LastValue { get; private set; }
public ulong ErrorCount { get; private set; }
public ulong ErrorCount => errorCount;
public ulong ResultCount { get; private set; }
public ulong ResultCount => resultCount;
ulong errorCount;
ulong resultCount;
public void OnCompleted()
{
@@ -21,13 +25,13 @@ namespace Tgstation.Server.Tests.Live
public void OnError(Exception error)
{
++ErrorCount;
Interlocked.Increment(ref errorCount);
LastError = error;
}
public void OnNext(T value)
{
++ResultCount;
Interlocked.Increment(ref resultCount);
LastValue = value;
}
}
@@ -53,8 +53,16 @@ namespace Tgstation.Server.Tests.Live
var expected = new PlatformIdentifier().IsWindows ? 108U : 107U;
// wait up to 10s
var lastSeen = observer.ResultCount;
for (var i = 0; i < 10 && observer.ResultCount < expected; ++i)
{
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
if (observer.ResultCount > lastSeen)
{
lastSeen = observer.ResultCount;
i = -1;
}
}
Assert.AreEqual(expected, observer.ResultCount); // sys user
observer.LastValue.EnsureNoErrors();