-
Notifications
You must be signed in to change notification settings - Fork 654
fix tests #15159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix tests #15159
Changes from all commits
ec00f39
c46b122
a2c6e30
f313eaf
32c8aea
2bcb444
3bbecab
bfb3891
6b574dd
abc9063
f392570
85bda77
32b8526
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Threading; | ||
using Dynamo.Configuration; | ||
|
@@ -15,7 +16,6 @@ | |
using Dynamo.Nodes; | ||
using Dynamo.Scheduler; | ||
using Dynamo.ViewModels; | ||
using Dynamo.Wpf.Utilities; | ||
using DynamoCoreWpfTests.Utility; | ||
using DynamoShapeManager; | ||
using DynamoUtilities; | ||
|
@@ -32,6 +32,11 @@ public class DynamoTestUIBase | |
protected DynamoView View { get; set; } | ||
protected DynamoModel Model { get; set; } | ||
|
||
// Use this flag to skip trying to execute all the dispatched operations during the test lifetime. | ||
// This flag should only be used very sparingly | ||
protected bool SkipDispatcherFlush = false; | ||
protected int DispatcherOpsCounter = 0; | ||
|
||
protected string ExecutingDirectory | ||
{ | ||
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } | ||
|
@@ -84,6 +89,11 @@ public virtual void Start() | |
View.Show(); | ||
|
||
SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will the current thread be typically in which this test fixture is set up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We run all our tests in a single thread (UI thread). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's surprising to me that if the tests are running in the UI thread, we have to do this explicitly. Perhaps this is a subtle difference between a main WPF app and a WPF test. |
||
|
||
if (!SkipDispatcherFlush) | ||
{ | ||
Dispatcher.CurrentDispatcher.Hooks.OperationPosted += Hooks_OperationPosted; | ||
} | ||
} | ||
|
||
protected static void RaiseLoadedEvent(FrameworkElement element) | ||
|
@@ -96,6 +106,14 @@ protected static void RaiseLoadedEvent(FrameworkElement element) | |
eventMethod.Invoke(element, new object[] { args }); | ||
} | ||
|
||
private void Hooks_OperationPosted(object sender, DispatcherHookEventArgs e) | ||
{ | ||
e.Operation.Task.ContinueWith((t) => { | ||
Interlocked.Decrement(ref DispatcherOpsCounter); | ||
}, TaskScheduler.Default); | ||
Interlocked.Increment(ref DispatcherOpsCounter); | ||
} | ||
|
||
/// <summary> | ||
/// Derived test classes can override this method to provide different configurations. | ||
/// </summary> | ||
|
@@ -114,6 +132,13 @@ protected virtual DynamoModel.IStartConfiguration CreateStartConfiguration(IPath | |
[TearDown] | ||
public void Exit() | ||
{ | ||
if (!SkipDispatcherFlush) | ||
{ | ||
Dispatcher.CurrentDispatcher.Hooks.OperationPosted -= Hooks_OperationPosted; | ||
|
||
DispatcherUtil.DoEventsLoop(() => DispatcherOpsCounter == 0); | ||
} | ||
|
||
//Ensure that we leave the workspace marked as | ||
//not having changes. | ||
ViewModel.HomeSpace.HasUnsavedChanges = false; | ||
|
Uh oh!
There was an error while loading. Please reload this page.