Skip to content

Commit 1cae79c

Browse files
authored
Added test to run all encoding/decoding subtests at once in parallel to prove threadsafety (#31)
1 parent 9bda6a9 commit 1cae79c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

SharpToken.Tests/SharpToken.Tests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,31 @@ public void TestEncodingAndDecoding(Tuple<string, string, List<int>> resource)
3131
});
3232
}
3333

34+
[Test]
35+
public async Task TestEncodingAndDecodingInParallel()
36+
{
37+
var tasks = TestData.Select(_ => Task.Run(() =>
38+
{
39+
var (encodingName, textToEncode, expectedEncoded) = _;
40+
var encoding = GptEncoding.GetEncoding(encodingName);
41+
var encoded = encoding.Encode(textToEncode);
42+
var decodedText = encoding.Decode(encoded);
43+
return (textToEncode, encoded, expectedEncoded, decodedText);
44+
}));
45+
46+
await Task.WhenAll(tasks).ConfigureAwait(false);
47+
48+
foreach (var (textToEncode, encoded, expectedEncoded, decodedText) in tasks.Select(_ => _.Result))
49+
{
50+
Assert.Multiple(() =>
51+
{
52+
Assert.That(encoded, Is.EqualTo(expectedEncoded));
53+
Assert.That(decodedText, Is.EqualTo(textToEncode));
54+
});
55+
}
56+
}
57+
58+
3459
[Test]
3560
public void TestEncodingWithCustomAllowedSet()
3661
{

0 commit comments

Comments
 (0)