Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix debug output clear #1014

Merged
merged 29 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9f85245
Add thread safe string writer with asynclocal
nohwnd Apr 15, 2021
75bceff
Merge main
nohwnd Aug 24, 2021
85bd71e
Use task aware string writer to collect output
nohwnd Aug 25, 2021
41076e1
Move to shared implementation, and fix output
nohwnd Aug 25, 2021
b1bdcbe
Merge branch 'main' into thread-safe-string-writer
nohwnd Aug 25, 2021
1378e3b
Fix debug output
nohwnd Aug 25, 2021
5306d3e
Fixes for null ref and parallel collection
nohwnd Aug 25, 2021
c73f512
Merge branch 'main' into thread-safe-string-writer
nohwnd Nov 19, 2021
c8422ab
Split net451 platform services and add net461
nohwnd Nov 19, 2021
9ce33c9
Fix path
nohwnd Nov 19, 2021
0a97414
Fix tests
nohwnd Nov 19, 2021
f77108e
5 min timeout
nohwnd Nov 22, 2021
11c0b39
use awaiter
nohwnd Nov 22, 2021
65342ee
Output
nohwnd Nov 22, 2021
ffff013
Add using
nohwnd Nov 22, 2021
55a1e97
Switch tasks
nohwnd Nov 22, 2021
f87be81
timeout
nohwnd Nov 22, 2021
eb7f5d7
Merge branch 'main' into thread-safe-string-writer
nohwnd Nov 22, 2021
38214a8
Make getting string and clearing run under the same lock
nohwnd Nov 29, 2021
7e56cb8
Merge branch 'main' into parallel-output-debug-clear
nohwnd Nov 29, 2021
8a8e893
Tracer fix
nohwnd Dec 1, 2021
77f372f
Fix concurrency issue with clearing the string builder
nohwnd Dec 1, 2021
8550e70
Add output tests (and fix dictionary)
nohwnd Dec 2, 2021
8906664
Fix tests
nohwnd Dec 2, 2021
77e3260
Add longer delay
nohwnd Dec 2, 2021
452e0e2
Of course it only fails in CI
nohwnd Dec 2, 2021
6eb76d1
Use Trace for the tracing output, Debug is not output in Release conf…
nohwnd Dec 2, 2021
a20030b
Fix namespace
nohwnd Dec 2, 2021
aa694d2
Reduce parallel check
nohwnd Dec 2, 2021
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
12 changes: 4 additions & 8 deletions src/Adapter/MSTest.CoreAdapter/Execution/LogMessageListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,13 @@ public string DebugTrace

public string GetAndClearStandardOutput()
{
var output = this.redirectLoggerOut.ToString();
this.redirectLoggerOut.Clear();
var output = this.redirectLoggerOut.ToStringAndClear();
return output;
}

public string GetAndClearStandardError()
{
var output = this.redirectStdErr.ToString();
this.redirectStdErr.Clear();
var output = this.redirectStdErr.ToStringAndClear();
return output;
}

Expand All @@ -116,11 +114,9 @@ public string GetAndClearDebugTrace()
return null;
}

if (writer is StringWriter sw)
if (writer is ThreadSafeStringWriter tssw)
{
var sb = sw.GetStringBuilder();
var output = sb?.ToString();
sb?.Clear();
var output = tssw.ToStringAndClear();
return output;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ public void Clear()
}
}

public string ToStringAndClear()
{
lock (this.lockObject)
{
try
{
var sb = this.GetStringBuilder();
var output = sb.ToString();
sb.Clear();
return output;
}
catch (ObjectDisposedException)
{
return default(string);
}
}
}

/// <inheritdoc/>
public override void Write(char value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,27 @@ public override string ToString()
}
}

public void Clear()
public string ToStringAndClear()
{
lock (this.lockObject)
{
this.GetStringBuilderOrNull()?.Clear();
try
{
var sb = this.GetStringBuilderOrNull();

if (sb == null)
{
return default(string);
}

var output = sb.ToString();
sb.Clear();
return output;
}
catch (ObjectDisposedException)
{
return default(string);
}
}
}

Expand Down