-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ReadAllParallelAsync (multi-threaded parsing) (#52)
Co-authored-by: in0finite <[email protected]>
- Loading branch information
Showing
29 changed files
with
23,427 additions
and
25,835 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Diagnostics; | ||
using System.Text; | ||
|
||
namespace DemoFile.Test; | ||
|
||
[DebuggerDisplay("Count = {Count}")] | ||
public class DemoSnapshot | ||
{ | ||
private readonly Dictionary<DemoTick, List<string>> _items = new(); | ||
|
||
public int Count => _items.Count; | ||
|
||
public void Add(DemoTick tick, string details) | ||
{ | ||
if (!_items.TryGetValue(tick, out var tickItems)) | ||
{ | ||
_items[tick] = new List<string> {details}; | ||
} | ||
else if (!tickItems.Contains(details)) | ||
{ | ||
tickItems.Add(details); | ||
} | ||
} | ||
|
||
public void MergeFrom(DemoSnapshot other) | ||
{ | ||
foreach (var (tick, items) in other._items) | ||
{ | ||
foreach (var item in items) | ||
{ | ||
Add(tick, item); | ||
} | ||
} | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
var result = new StringBuilder(); | ||
|
||
foreach (var (tick, items) in _items.OrderBy(kvp => kvp.Key)) | ||
{ | ||
foreach (var item in items) | ||
{ | ||
result.Append($"[{tick}] {item}"); | ||
|
||
if (item[^1] != '\n') | ||
{ | ||
result.AppendLine(); | ||
} | ||
} | ||
} | ||
|
||
return result.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 20 additions & 29 deletions
49
src/DemoFile.Test/Integration/DemoEventsIntegrationTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,42 @@ | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Text.Json; | ||
|
||
namespace DemoFile.Test.Integration; | ||
|
||
[TestFixture(true)] | ||
[TestFixture(false)] | ||
[TestFixtureSource(typeof(GlobalUtil), nameof(ParseModes))] | ||
public class DemoEventsIntegrationTest | ||
{ | ||
private readonly bool _readAll; | ||
private readonly ParseMode _mode; | ||
|
||
public DemoEventsIntegrationTest(bool readAll) | ||
public DemoEventsIntegrationTest(ParseMode mode) | ||
{ | ||
_readAll = readAll; | ||
_mode = mode; | ||
} | ||
|
||
[Test] | ||
public async Task DemoFileInfo() | ||
{ | ||
// Arrange | ||
var snapshot = new StringBuilder(); | ||
var demo = new DemoParser(); | ||
|
||
demo.DemoEvents.DemoFileInfo += e => | ||
DemoSnapshot ParseSection(DemoParser demo) | ||
{ | ||
snapshot.AppendLine($"[{demo.CurrentDemoTick}/{demo.CurrentGameTick}] TickCount={demo.TickCount}"); | ||
snapshot.AppendLine($"[{demo.CurrentDemoTick}/{demo.CurrentGameTick}] DemoFileInfo: {JsonSerializer.Serialize(e, DemoJson.SerializerOptions)}"); | ||
}; | ||
var snapshot = new DemoSnapshot(); | ||
|
||
demo.PacketEvents.SvcServerInfo += e => | ||
{ | ||
snapshot.AppendLine($"[{demo.CurrentDemoTick}/{demo.CurrentGameTick}] SvcServerInfo: {JsonSerializer.Serialize(e, DemoJson.SerializerOptions)}"); | ||
}; | ||
demo.DemoEvents.DemoFileInfo += e => | ||
{ | ||
snapshot.Add(demo.CurrentDemoTick, $"GameTick: {demo.CurrentGameTick}, TickCount: {demo.TickCount}, DemoFileInfo: {JsonSerializer.Serialize(e, DemoJson.SerializerOptions)}"); | ||
}; | ||
|
||
// Act | ||
if (_readAll) | ||
{ | ||
await demo.ReadAllAsync(GotvCompetitiveProtocol13963, default); | ||
} | ||
else | ||
{ | ||
await demo.StartReadingAsync(GotvCompetitiveProtocol13963, default); | ||
while (await demo.MoveNextAsync(default)) | ||
demo.PacketEvents.SvcServerInfo += e => | ||
{ | ||
} | ||
snapshot.Add(demo.CurrentDemoTick, $"GameTick: {demo.CurrentGameTick}, SvcServerInfo: {JsonSerializer.Serialize(e, DemoJson.SerializerOptions)}"); | ||
}; | ||
|
||
return snapshot; | ||
} | ||
|
||
// Act | ||
var snapshot = await Parse(_mode, GotvCompetitiveProtocol13963, ParseSection); | ||
|
||
// Assert | ||
Snapshot.Assert(snapshot.ToString()); | ||
Snapshot.Assert(snapshot); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.