-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Add System.ComponentModel.EventBasedAsync tests #20931
Conversation
I may need some help here... I get the following errors when I use
If anyone knows what I've done wrong, I'd appreciate some assistance |
The lambda you give to RemoteInvoke must not close over anything. We only marshal the name of the lambda method plus any arguments explicitly passed as arguments to RemoteInvoke; when the display class is instantiated in the remote process, the lifted fields accessed by the display class would be null. |
That'd be it, thanks! |
{ | ||
MethodInfo finalizer = typeof(AsyncOperation).GetMethod("Finalize", BindingFlags.NonPublic | BindingFlags.Instance); | ||
Assert.NotNull(finalizer); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be better to actually test the functionality of the finalizer rather than testing for its presence via reflection and invoking it explicitly as is done below. You could do this by creating your own sync ctx that the finalizer will call back to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I'm wrong, the tests do exactly that. They use the following sync context that the finalizer does indeed call back to when we manually invoke it. This test you commented on is just a sanity checker.
public class OperationCompletedTracker : SynchronizationContext
{
public int OperationCompletedCounter { get; set; }
public override void OperationCompleted() => OperationCompletedCounter++;
}
In terms of guaranteeing that the finalizer is invoked without reflection, I don't know what the best way to do that is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They use the following sync context that the finalizer does indeed call back to when we manually invoke it.
But we shouldn't manually invoke it via reflection. You instead need to ensure that the object is collectable (e.g. ctor it in a helper method to ensure the JIT doesn't artificially extend its lifetime), and then force collection with GC.Collect and wait for finalizers to run with GC.WaitForPendingFinalizers.
Assert.Null(e.Result); | ||
Assert.False(backgroundWorker.IsBusy); | ||
}; | ||
backgroundWorker.RunWorkerAsync(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't going to play particularly nicely with xunit. Any failures are going to happen asynchronously, maybe after the test has already completed, and in fact the process may shut down before it gets a chance to run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I've updated the test to handle this fact, and also to make sure that the completed handler was called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than Stephen's comments LGTM.
The tests you're adding use RemoteExecutor and that will break this tests for UWP since RemoteExecutor is broken. There is a PR open to fix that, so I would like this PR to be merged after the other one since we are trying to get our test failures in UWP to 0 so that we can enable a CI leg. #21014 this is the PR that we should wait for. |
Sure thing @safern |
Test Innerloop OSX10.12 Release x64 Build and Test |
1 similar comment
Test Innerloop OSX10.12 Release x64 Build and Test |
I've removed the reflection - I think the blocker for this PR for RemoteExecutorTestBase is no more, right? |
I'll pull your changes and confirm locally that the tests don't cause any regression for uap, so that we don't go backwards in the progress we've made. |
@safern I know it was the weekend, but let me know how it goes :) |
Taking a look now. I'll let you know :) |
They pass in Uap so I will merge :) Thanks @hughbe |
* Add System.ComponentModel.EventBasedAsync tests Commit migrated from dotnet/corefx@e4a633a
This increases CC to 100% in the library