Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public string? Id
}

public bool IsAllDataRequested { get { throw null; } set { throw null; } }
public bool IsStopped { get { throw null; } }
public System.Diagnostics.ActivityIdFormat IdFormat { get { throw null; } }
public System.Diagnostics.ActivityKind Kind { get { throw null; } }
public string OperationName { get { throw null; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,9 @@ public void Stop()
return;
}

if (!IsFinished)
if (!IsStopped)
{
IsFinished = true;
IsStopped = true;

if (Duration == TimeSpan.Zero)
{
Expand Down Expand Up @@ -951,7 +951,7 @@ internal static bool TryConvertIdToContext(string traceParent, string? traceStat
/// </summary>
public void Dispose()
{
if (!IsFinished)
if (!IsStopped)
{
Stop();
}
Expand Down Expand Up @@ -1232,7 +1232,7 @@ private static unsafe long GetRandomNumber()

private static bool ValidateSetCurrent(Activity? activity)
{
bool canSet = activity == null || (activity.Id != null && !activity.IsFinished);
bool canSet = activity == null || (activity.Id != null && !activity.IsStopped);
if (!canSet)
{
NotifyError(new InvalidOperationException(SR.ActivityNotRunning));
Expand Down Expand Up @@ -1298,18 +1298,21 @@ private bool W3CIdFlagsSet
get => (_w3CIdFlags & ActivityTraceFlagsIsSet) != 0;
}

private bool IsFinished
/// <summary>
/// Indicate if the this Activity object is stopped
Comment thread
tarekgh marked this conversation as resolved.
Outdated
/// </summary>
public bool IsStopped
{
get => (_state & State.IsFinished) != 0;
set
get => (_state & State.IsStopped) != 0;
private set
{
if (value)
{
_state |= State.IsFinished;
_state |= State.IsStopped;
}
else
{
_state &= ~State.IsFinished;
_state &= ~State.IsStopped;
}
}
}
Expand Down Expand Up @@ -1623,7 +1626,7 @@ private enum State : byte
FormatW3C = 0b_0_00000_10,
FormatFlags = 0b_0_00000_11,

IsFinished = 0b_1_00000_00,
IsStopped = 0b_1_00000_00,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ public void ActivityIdOverflow()
Assert.Equal('#', activity.Id[activity.Id.Length - 1]);
}


/// <summary>
/// Tests activity start and stop
/// Checks Activity.Current correctness, Id generation
Expand All @@ -320,6 +319,31 @@ public void StartStop()
Assert.Null(Activity.Current);
}

/// <summary>
/// Tests Activity.IsStopped
/// </summary>
[Fact]
public void IsStoppedTest()
{
var activity = new Activity("activity");
Comment thread
tarekgh marked this conversation as resolved.
Outdated
Assert.False(activity.IsStopped);
activity.Start();
Assert.False(activity.IsStopped);
Assert.Equal(TimeSpan.Zero, activity.Duration);
activity.Stop();
Assert.NotEqual(TimeSpan.Zero, activity.Duration);
Assert.True(activity.IsStopped);

activity = new Activity("activity");
Assert.False(activity.IsStopped);
activity.Start();
Assert.False(activity.IsStopped);
activity.SetEndTime(DateTime.UtcNow.AddMinutes(1)); // Setting end time shouldn't mark the activity as stopped
Assert.False(activity.IsStopped);
activity.Stop();
Assert.True(activity.IsStopped);
}

/// <summary>
/// Tests Id generation
/// </summary>
Expand Down