microsoft / RTVS

R Tools for Visual Studio.
MIT License
390 stars 110 forks source link

ConnectionManagerTest.DisconnectAsync_Canceled test needs UI thread #3737

Open MikhailArkhipov opened 7 years ago

MikhailArkhipov commented 7 years ago

     ConnectionManagerTest.DisconnectAsync_Canceled [FAIL]
[xUnit.net 00:05:07.8126757]       System.InvalidOperationException : The calling thread must be STA, because many UI components require this.
[xUnit.net 00:05:07.8145445]       Stack Trace:
[xUnit.net 00:05:07.8152665]            at System.Windows.Input.InputManager..ctor()
[xUnit.net 00:05:07.8158609]            at System.Windows.Input.InputManager.GetCurrentInputManagerImpl()
[xUnit.net 00:05:07.8163674]            at System.Windows.Input.KeyboardNavigation..ctor()
[xUnit.net 00:05:07.8169029]            at System.Windows.FrameworkElement.FrameworkServices..ctor()
[xUnit.net 00:05:07.8174272]            at System.Windows.FrameworkElement.EnsureFrameworkServices()
[xUnit.net 00:05:07.8179342]            at System.Windows.FrameworkElement..ctor()
[xUnit.net 00:05:07.8184673]            at System.Windows.Controls.Control..ctor()
[xUnit.net 00:05:07.8189577]            at System.Windows.Controls.UserControl..ctor()
[xUnit.net 00:05:07.8194398]         F:\RTVS\src\Windows\R\Components\Impl\ConnectionManager\Implementation\View\ConnectionStatusBar.xaml.cs(16,0): at Microsoft.R.Components.ConnectionManager.Implementation.View.ConnectionStatusBar..ctor()
[xUnit.net 00:05:07.8199524]         F:\RTVS\src\Windows\R\Components\Impl\ConnectionManager\Implementation\ConnectionManager.cs(93,0): at Microsoft.R.Components.ConnectionManager.Implementation.ConnectionManager.<CompleteInitializationAsync>d__41.MoveNext()
[xUnit.net 00:05:07.8204315]         --- End of stack trace from previous location where exception was thrown ---
[xUnit.net 00:05:07.8208881]            at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[xUnit.net 00:05:07.8214089]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[xUnit.net 00:05:07.8218573]            at System.Runtime.CompilerServices.TaskAwaiter.GetResult()```
AlexanderSher commented 7 years ago

Not sure about it, need to find out why ConnectionStatusBar..ctor() is called

MikhailArkhipov commented 7 years ago

I'll have more info later, re-running whole stack

MikhailArkhipov commented 7 years ago
    Microsoft.R.Components.Windows.dll!Microsoft.R.Components.ConnectionManager.Implementation.ConnectionManager.CompleteInitializationAsync() Line 92  C#
    Microsoft.R.Components.Windows.dll!Microsoft.R.Components.ConnectionManager.Implementation.ConnectionManager.ConnectionManager(Microsoft.R.Components.StatusBar.IStatusBar statusBar, Microsoft.R.Components.Settings.IRSettings settings, Microsoft.R.Components.InteractiveWorkflow.IRInteractiveWorkflowVisual interactiveWorkflow) Line 88  C#
    Microsoft.R.Components.Windows.dll!Microsoft.R.Components.ConnectionManager.Implementation.ConnectionManagerProvider.CreateConnectionManager(Microsoft.R.Components.InteractiveWorkflow.IRInteractiveWorkflow interactiveWorkflow) Line 20  C#
>   Microsoft.R.Components.Windows.dll!Microsoft.R.Components.InteractiveWorkflow.Implementation.RInteractiveWorkflow.RInteractiveWorkflow(Microsoft.R.Components.ConnectionManager.IConnectionManagerProvider connectionsProvider, Microsoft.R.Components.History.IRHistoryProvider historyProvider, Microsoft.R.Components.PackageManager.IRPackageManagerProvider packagesProvider, Microsoft.R.Components.Plots.IRPlotManagerProvider plotsProvider, Microsoft.R.Components.InteractiveWorkflow.IActiveWpfTextViewTracker activeTextViewTracker, Microsoft.R.Components.InteractiveWorkflow.IDebuggerModeTracker debuggerModeTracker, Microsoft.Common.Core.Shell.ICoreShell coreShell) Line 70 C#
    Microsoft.R.Components.Test.dll!Microsoft.R.Components.Test.Fakes.InteractiveWindow.TestRInteractiveWorkflowProvider.CreateRInteractiveWorkflow() Line 83   C#
    [External Code] 
    Microsoft.R.Components.Test.dll!Microsoft.R.Components.Test.Fakes.InteractiveWindow.TestRInteractiveWorkflowProvider.Microsoft.R.Components.InteractiveWorkflow.IRInteractiveWorkflowVisualProvider.GetOrCreate() Line 75   C#
    Microsoft.R.Components.Test.dll!Microsoft.R.Components.Test.Fakes.InteractiveWindow.TestRInteractiveWorkflowProvider.Microsoft.R.Components.InteractiveWorkflow.IRInteractiveWorkflowProvider.GetOrCreate() Line 78 C#
MikhailArkhipov commented 7 years ago

Looks like 0fedd5b2 , change to RSessionChangeWatcher which now calls Workflow = workflowProvider.GetOrCreate(); in ctor causing CM and friends to be pulled in.

AlexanderSher commented 7 years ago

Ok, looks like I understand why it is happening.

At the end of the test, we call TestMainThread.CancelPendingTasks to cancel all threads that are currently waiting for switch to UI thread, but they don't throw exception because of _cancellationToken.ThrowIfCancellationRequested()

I'll fix this.

MikhailArkhipov commented 7 years ago

I added lazy creation of UI elements so they don't get created in blind tests

MikhailArkhipov commented 7 years ago

Threading issues still happen when tests run in a group. Primarily 'another thread owns it` from WPF dispatcher checks