Fix possible race condition in DummyChatProvider

This commit is contained in:
Jordan Dominion
2023-07-08 11:55:38 -04:00
parent 6e1b6a6f67
commit 05a4f89a26
@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -36,7 +37,7 @@ namespace Tgstation.Server.Tests.Live
readonly ICryptographySuite cryptographySuite;
readonly CancellationTokenSource randomMessageCts;
readonly Task randomMessageTask;
readonly Dictionary<ulong, ChannelRepresentation> knownChannels;
readonly ConcurrentDictionary<ulong, ChannelRepresentation> knownChannels;
bool connectedOnce;
bool connected;
@@ -71,7 +72,7 @@ namespace Tgstation.Server.Tests.Live
this.commands = commands ?? throw new ArgumentNullException(nameof(commands));
this.random = random ?? throw new ArgumentNullException(nameof(random));
knownChannels = new Dictionary<ulong, ChannelRepresentation>();
knownChannels = new ();
randomMessageCts = new CancellationTokenSource();
randomMessageTask = RandomMessageLoop(this.randomMessageCts.Token);
}
@@ -189,8 +190,7 @@ namespace Tgstation.Server.Tests.Live
Tag = channel.Tag,
};
knownChannels.Remove(channelId);
knownChannels.Add(channelId, entry);
knownChannels[channelId] = entry;
return CloneChannel(entry);
}
@@ -255,7 +255,7 @@ namespace Tgstation.Server.Tests.Live
// isAdmin and Tag populated by manager
};
knownChannels.Add(channelId, channel);
knownChannels[channelId] = channel;
}
else
{