Skip to content

Commit 502a65c

Browse files
Copilotbrianrob
andcommitted
Add using statements for MemoryStream disposal
Co-authored-by: brianrob <[email protected]>
1 parent 9430360 commit 502a65c

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

src/TraceEvent/TraceEvent.Tests/Regression/RecursiveCallTest.cs

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -179,58 +179,58 @@ public void RecursiveCallsWithMutableTraceEventStackSource()
179179
writer.WriteEndBlock();
180180

181181
// Convert nettrace to EventPipeEventSource
182-
MemoryStream nettraceStream = new MemoryStream(writer.ToArray());
182+
using MemoryStream nettraceStream = new MemoryStream(writer.ToArray());
183183
TraceEventDispatcher eventSource = new EventPipeEventSource(nettraceStream);
184184

185185
// Convert to in-memory ETLX
186-
MemoryStream etlxStream = new MemoryStream();
186+
using MemoryStream etlxStream = new MemoryStream();
187187
TraceLog.CreateFromEventPipeEventSources(eventSource, new IOStreamStreamWriter(etlxStream, SerializationSettings.Default, leaveOpen: true), null);
188188
etlxStream.Position = 0;
189189

190190
// Create TraceLog from in-memory ETLX
191191
using (var traceLog = new TraceLog(etlxStream))
192192
{
193-
// Create MutableTraceEventStackSource and reproduce the exact issue scenario
194-
var stackSource = new MutableTraceEventStackSource(traceLog);
195-
196-
// This reproduces the exact code from the issue:
197-
var sample = new StackSourceSample(stackSource);
198-
sample.StackIndex = stackSource.Interner.CallStackIntern(
199-
stackSource.Interner.FrameIntern("X"), sample.StackIndex);
200-
sample.StackIndex = stackSource.Interner.CallStackIntern(
201-
stackSource.Interner.FrameIntern("X"), sample.StackIndex);
202-
sample.TimeRelativeMSec = 1.0;
203-
sample.Metric = 1.0f;
204-
sample.Count = 1;
205-
stackSource.AddSample(sample);
206-
stackSource.DoneAddingSamples();
207-
208-
// Build CallTree and verify structure
209-
var callTree = new CallTree(ScalingPolicyKind.ScaleToData);
210-
callTree.StackSource = stackSource;
211-
212-
var root = callTree.Root;
213-
Assert.NotNull(root);
214-
215-
// Test CallerCalleeNode for "X" - this is the main test
216-
// The CallerCalleeNode should correctly identify recursive relationships
217-
var callerCalleeNode = new CallerCalleeNode("X", callTree);
218-
219-
// The key assertions: X should appear as both caller and callee
220-
// This tests that the recursive call (X -> X) is properly represented
221-
var xCaller = callerCalleeNode.Callers.FirstOrDefault(c => c.Name == "X");
222-
Assert.NotNull(xCaller);
223-
Assert.True(xCaller.InclusiveMetric > 0,
224-
$"Recursive caller 'X' should have positive metric, got {xCaller.InclusiveMetric}");
225-
Assert.False(float.IsNaN(xCaller.InclusiveMetric),
226-
"Recursive caller 'X' has NaN inclusive metric");
227-
228-
var xCallee = callerCalleeNode.Callees.FirstOrDefault(c => c.Name == "X");
229-
Assert.NotNull(xCallee);
230-
Assert.True(xCallee.InclusiveMetric > 0,
231-
$"Recursive callee 'X' should have positive metric, got {xCallee.InclusiveMetric}");
232-
Assert.False(float.IsNaN(xCallee.InclusiveMetric),
233-
"Recursive callee 'X' has NaN inclusive metric");
193+
// Create MutableTraceEventStackSource and reproduce the exact issue scenario
194+
var stackSource = new MutableTraceEventStackSource(traceLog);
195+
196+
// This reproduces the exact code from the issue:
197+
var sample = new StackSourceSample(stackSource);
198+
sample.StackIndex = stackSource.Interner.CallStackIntern(
199+
stackSource.Interner.FrameIntern("X"), sample.StackIndex);
200+
sample.StackIndex = stackSource.Interner.CallStackIntern(
201+
stackSource.Interner.FrameIntern("X"), sample.StackIndex);
202+
sample.TimeRelativeMSec = 1.0;
203+
sample.Metric = 1.0f;
204+
sample.Count = 1;
205+
stackSource.AddSample(sample);
206+
stackSource.DoneAddingSamples();
207+
208+
// Build CallTree and verify structure
209+
var callTree = new CallTree(ScalingPolicyKind.ScaleToData);
210+
callTree.StackSource = stackSource;
211+
212+
var root = callTree.Root;
213+
Assert.NotNull(root);
214+
215+
// Test CallerCalleeNode for "X" - this is the main test
216+
// The CallerCalleeNode should correctly identify recursive relationships
217+
var callerCalleeNode = new CallerCalleeNode("X", callTree);
218+
219+
// The key assertions: X should appear as both caller and callee
220+
// This tests that the recursive call (X -> X) is properly represented
221+
var xCaller = callerCalleeNode.Callers.FirstOrDefault(c => c.Name == "X");
222+
Assert.NotNull(xCaller);
223+
Assert.True(xCaller.InclusiveMetric > 0,
224+
$"Recursive caller 'X' should have positive metric, got {xCaller.InclusiveMetric}");
225+
Assert.False(float.IsNaN(xCaller.InclusiveMetric),
226+
"Recursive caller 'X' has NaN inclusive metric");
227+
228+
var xCallee = callerCalleeNode.Callees.FirstOrDefault(c => c.Name == "X");
229+
Assert.NotNull(xCallee);
230+
Assert.True(xCallee.InclusiveMetric > 0,
231+
$"Recursive callee 'X' should have positive metric, got {xCallee.InclusiveMetric}");
232+
Assert.False(float.IsNaN(xCallee.InclusiveMetric),
233+
"Recursive callee 'X' has NaN inclusive metric");
234234
}
235235
}
236236

0 commit comments

Comments
 (0)