Skip to content

Commit 5bbb95f

Browse files
committed
Option to exclude blockReceivedEvents from transcript
1 parent 5aa3edb commit 5bbb95f

File tree

6 files changed

+47
-18
lines changed

6 files changed

+47
-18
lines changed

ProjectPlugins/CodexPlugin/OverwatchSupport/CodexLogConverter.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@ namespace CodexPlugin.OverwatchSupport
88
public class CodexLogConverter
99
{
1010
private readonly ITranscriptWriter writer;
11+
private readonly CodexTranscriptWriterConfig config;
1112
private readonly IdentityMap identityMap;
1213

13-
public CodexLogConverter(ITranscriptWriter writer, IdentityMap identityMap)
14+
public CodexLogConverter(ITranscriptWriter writer, CodexTranscriptWriterConfig config, IdentityMap identityMap)
1415
{
1516
this.writer = writer;
17+
this.config = config;
1618
this.identityMap = identityMap;
1719
}
1820

1921
public void ProcessLog(IDownloadedLog log)
2022
{
2123
var name = DetermineName(log);
2224
var identityIndex = identityMap.GetIndex(name);
23-
var runner = new ConversionRunner(writer, identityMap, log.ContainerName, identityIndex);
25+
var runner = new ConversionRunner(writer, config, identityMap, identityIndex);
2426
runner.Run(log);
2527
}
2628

@@ -37,22 +39,27 @@ public class ConversionRunner
3739
{
3840
private readonly ITranscriptWriter writer;
3941
private readonly IdentityMap nameIdMap;
40-
private readonly string name;
4142
private readonly int nodeIdentityIndex;
42-
private readonly ILineConverter[] converters = new ILineConverter[]
43-
{
44-
new BlockReceivedLineConverter(),
45-
new BootstrapLineConverter(),
46-
new DialSuccessfulLineConverter(),
47-
new PeerDroppedLineConverter()
48-
};
43+
private readonly ILineConverter[] converters;
4944

50-
public ConversionRunner(ITranscriptWriter writer, IdentityMap nameIdMap, string name, int nodeIdentityIndex)
45+
public ConversionRunner(ITranscriptWriter writer, CodexTranscriptWriterConfig config, IdentityMap nameIdMap, int nodeIdentityIndex)
5146
{
52-
this.name = name;
5347
this.nodeIdentityIndex = nodeIdentityIndex;
5448
this.writer = writer;
5549
this.nameIdMap = nameIdMap;
50+
51+
converters = CreateConverters(config).ToArray();
52+
}
53+
54+
private IEnumerable<ILineConverter> CreateConverters(CodexTranscriptWriterConfig config)
55+
{
56+
if (config.IncludeBlockReceivedEvents)
57+
{
58+
yield return new BlockReceivedLineConverter();
59+
}
60+
yield return new BootstrapLineConverter();
61+
yield return new DialSuccessfulLineConverter();
62+
yield return new PeerDroppedLineConverter();
5663
}
5764

5865
public void Run(IDownloadedLog log)

ProjectPlugins/CodexPlugin/OverwatchSupport/CodexTranscriptWriter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ public class CodexTranscriptWriter : ICodexHooksProvider
1010
{
1111
private const string CodexHeaderKey = "cdx_h";
1212
private readonly ILog log;
13+
private readonly CodexTranscriptWriterConfig config;
1314
private readonly ITranscriptWriter writer;
1415
private readonly CodexLogConverter converter;
1516
private readonly IdentityMap identityMap = new IdentityMap();
1617
private readonly KademliaPositionFinder positionFinder = new KademliaPositionFinder();
1718

18-
public CodexTranscriptWriter(ILog log, ITranscriptWriter transcriptWriter)
19+
public CodexTranscriptWriter(ILog log, CodexTranscriptWriterConfig config, ITranscriptWriter transcriptWriter)
1920
{
2021
this.log = log;
22+
this.config = config;
2123
writer = transcriptWriter;
22-
converter = new CodexLogConverter(writer, identityMap);
24+
converter = new CodexLogConverter(writer, config, identityMap);
2325
}
2426

2527
public void Finalize(string outputFilepath)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace CodexPlugin.OverwatchSupport
2+
{
3+
public class CodexTranscriptWriterConfig
4+
{
5+
public CodexTranscriptWriterConfig(bool includeBlockReceivedEvents)
6+
{
7+
IncludeBlockReceivedEvents = includeBlockReceivedEvents;
8+
}
9+
10+
public bool IncludeBlockReceivedEvents { get; }
11+
}
12+
}

ProjectPlugins/CodexPlugin/OverwatchSupport/IdentityMap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void Add(CodexNodeIdentity identity)
2727
nodes.Add(identity);
2828

2929
shortToLong.Add(CodexUtils.ToShortId(identity.PeerId), identity.PeerId);
30-
shortToLong.Add(CodexUtils.ToShortId(identity.NodeId), identity.NodeId);
30+
shortToLong.Add(CodexUtils.ToNodeIdShortId(identity.NodeId), identity.NodeId);
3131
}
3232

3333
public CodexNodeIdentity[] Get()

Tests/CodexTests/BasicTests/MarketplaceTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class MarketplaceTests : AutoBootstrapDistTest
1313
{
1414
[Test]
1515
[Combinatorial]
16+
[CreateTranscript(nameof(MarketplaceTests), includeBlockReceivedEvents: false)]
1617
public void MarketplaceExample(
1718
[Values(64)] int numBlocks,
1819
[Values(0)] int plusSizeKb,

Tests/CodexTests/CodexDistTest.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,15 @@ protected virtual void OnCodexSetup(ICodexSetup setup)
136136

137137
private void SetupTranscript(TestLifecycle lifecycle)
138138
{
139-
if (GetTranscriptAttributeOfCurrentTest() == null) return;
139+
var attr = GetTranscriptAttributeOfCurrentTest();
140+
if (attr == null) return;
141+
142+
var config = new CodexTranscriptWriterConfig(
143+
attr.IncludeBlockReceivedEvents
144+
);
140145

141146
var log = new LogPrefixer(lifecycle.Log, "(Transcript) ");
142-
var writer = new CodexTranscriptWriter(log, Transcript.NewWriter(log));
147+
var writer = new CodexTranscriptWriter(log, config, Transcript.NewWriter(log));
143148
Ci.SetCodexHooksProvider(writer);
144149
writers.Add(lifecycle, writer);
145150
}
@@ -190,11 +195,13 @@ private string GetOutputFullPath(TestLifecycle lifecycle, CreateTranscriptAttrib
190195
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
191196
public class CreateTranscriptAttribute : PropertyAttribute
192197
{
193-
public CreateTranscriptAttribute(string outputFilename)
198+
public CreateTranscriptAttribute(string outputFilename, bool includeBlockReceivedEvents = true)
194199
{
195200
OutputFilename = outputFilename;
201+
IncludeBlockReceivedEvents = includeBlockReceivedEvents;
196202
}
197203

198204
public string OutputFilename { get; }
205+
public bool IncludeBlockReceivedEvents { get; }
199206
}
200207
}

0 commit comments

Comments
 (0)