mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-26 22:48:20 +01:00
Fix potential race conditions with user subscription test
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user