-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use reference instead of definition when using message in async state…
… machine (#527)
- Loading branch information
1 parent
4bb81b7
commit 398f36d
Showing
6 changed files
with
208 additions
and
133 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
151 changes: 151 additions & 0 deletions
151
Tests/AssemblyTesterSets/WithoutInterceptorTests.async.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 |
---|---|---|
@@ -0,0 +1,151 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
public partial class WithoutInterceptorTests | ||
{ | ||
[Fact] | ||
public void MethodWithEmptyAsync() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
var task = (Task)instance.MethodWithEmptyAsync(); | ||
task.Wait(); | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithAsyncMethod.MethodWithEmptyAsync ", message.First()); | ||
} | ||
|
||
[Fact] | ||
public void ClassWithAsyncMethod() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
var task = (Task)instance.MethodWithAwaitAsync(); | ||
task.Wait(); | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithAsyncMethod.MethodWithAwaitAsync ", message.First()); | ||
} | ||
|
||
[Fact] | ||
public void ClassWithAsyncMethodThatThrowsException() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
try | ||
{ | ||
var task = (Task)instance.MethodWithAwaitAndExceptionAsync(); | ||
task.Wait(); | ||
} | ||
catch (Exception) | ||
{ | ||
// Expected | ||
} | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithAsyncMethod.MethodWithAwaitAndExceptionAsync ", message.First()); | ||
} | ||
|
||
[Fact] | ||
public async Task ClassWithGenericTaskWithoutMessageAsyncMethod() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithGenericResultAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = await TraceRunner.CaptureAsync(async () => | ||
{ | ||
var task = (Task)instance.DoSomethingWithoutMessageAsync<int>(); | ||
await task; | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithGenericResultAsyncMethod.DoSomethingWithoutMessageAsync", message.First()); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void ClassWithAsyncMethodWithFastPath(bool recurse) | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
var task = (Task)instance.MethodWithFastPathAsync(recurse); | ||
task.Wait(); | ||
}); | ||
|
||
Assert.Equal(recurse ? 2 : 1, message.Count); | ||
Assert.StartsWith("ClassWithAsyncMethod.MethodWithFastPathAsync ", message.First()); | ||
} | ||
|
||
[Fact] | ||
public void ClassWithExceptionAsyncMethod() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
var task = (Task)instance.ComplexMethodWithAwaitAsync(-1); | ||
task.Wait(); | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithAsyncMethod.ComplexMethodWithAwaitAsync ", message.First()); | ||
} | ||
|
||
[Fact] | ||
public void ClassWithFastComplexAsyncMethod() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
var task = (Task)instance.ComplexMethodWithAwaitAsync(0); | ||
task.Wait(); | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithAsyncMethod.ComplexMethodWithAwaitAsync ", message.First()); | ||
} | ||
|
||
[Fact] | ||
public void ClassWithMediumComplexAsyncMethod() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
var task = (Task)instance.ComplexMethodWithAwaitAsync(2); | ||
task.Wait(); | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithAsyncMethod.ComplexMethodWithAwaitAsync ", message.First()); | ||
} | ||
|
||
[Fact] | ||
public void ClassWithSlowComplexAsyncMethod() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
var task = (Task)instance.ComplexMethodWithAwaitAsync(100); | ||
task.Wait(); | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithAsyncMethod.ComplexMethodWithAwaitAsync ", message.First()); | ||
} | ||
} |
Oops, something went wrong.