public async Task SwitchToTheSameBroker_NoSessions() { using (var sessionProvider = new RSessionProvider(_services)) { var switch1Task = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchToTheSameBroker_NoSessions)); var switch2Task = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchToTheSameBroker_NoSessions)); await ParallelTools.WhenAll(30000, switch1Task, switch2Task); switch1Task.Status.Should().Be(TaskStatus.RanToCompletion); switch2Task.Status.Should().Be(TaskStatus.RanToCompletion); } }
private async Task InitializeGraphicsDevice() { var deviceCreatedTask = EventTaskSources.IRPlotManager.DeviceAdded.Create(_plotManager); var deviceChangedTask = EventTaskSources.IRPlotManager.ActiveDeviceChanged.Create(_plotManager); var eval = _workflow.ActiveWindow.InteractiveWindow.Evaluator; var result = await eval.ExecuteCodeAsync("dev.new()\n"); result.IsSuccessful.Should().BeTrue(); await ParallelTools.WhenAll(20000, deviceCreatedTask, deviceChangedTask); }
public async Task SwitchAvailableLoadedInstalledAsync() { var t1 = InUI(() => _packageManagerViewModel.SwitchToAvailablePackagesAsync()); var t2 = InUI(() => _packageManagerViewModel.SwitchToLoadedPackagesAsync()); var t3 = InUI(() => _packageManagerViewModel.SwitchToInstalledPackagesAsync()); await ParallelTools.WhenAll(t1, t2, t3); _packageManagerViewModel.IsLoading.Should().BeFalse(); _packageManagerViewModel.SelectedPackage.Should().NotBeNull(); _packageManagerViewModel.Items.Should().OnlyContain(o => ((IRPackageViewModel)o).IsInstalled) .And.Contain(_packageManagerViewModel.SelectedPackage); }
public async Task SwitchLoadedInstalledAvailableAsync() { var t1 = InUI(() => _packageManagerViewModel.SwitchToLoadedPackagesAsync()); var t2 = InUI(() => _packageManagerViewModel.SwitchToInstalledPackagesAsync()); var t3 = InUI(() => _packageManagerViewModel.SwitchToAvailablePackagesAsync()); await ParallelTools.WhenAll(t1, t2, t3); var expected = new [] { "NotAvailable1", "NotAvailable2", "rtvslib1" }; _packageManagerViewModel.IsLoading.Should().BeFalse(); _packageManagerViewModel.SelectedPackage.Should().NotBeNull(); _packageManagerViewModel.Items.Should().Equal(expected, (o, n) => ((IRPackageViewModel)o).Name.EqualsOrdinal(n)) .And.Contain(_packageManagerViewModel.SelectedPackage); }
public async Task ConnectWhenSwitching() { using (var sessionProvider = new RSessionProvider(_services)) { var session1 = sessionProvider.GetOrCreate(nameof(ConnectWhenSwitching) + 1); var session2 = sessionProvider.GetOrCreate(nameof(ConnectWhenSwitching) + 2); var switchTask = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(ConnectWhenSwitching)); var startHost1Task = Task.Delay(50).ContinueWith(t => session1.EnsureHostStartedAsync(new RHostStartupInfo(), null, 1000)).Unwrap(); var startHost2Task = Task.Delay(100).ContinueWith(t => session2.EnsureHostStartedAsync(new RHostStartupInfo(), null, 1000)).Unwrap(); await ParallelTools.WhenAll(30000, switchTask, startHost1Task, startHost2Task); startHost1Task.Should().BeRanToCompletion(); startHost2Task.Should().BeRanToCompletion(); await ParallelTools.WhenAll(30000, session1.HostStarted, session2.HostStarted); } }
public async Task SwitchToTheSameBroker() { using (var sessionProvider = new RSessionProvider(_services)) { var session = sessionProvider.GetOrCreate(nameof(SwitchToTheSameBroker)); session.RestartOnBrokerSwitch = true; await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchToTheSameBroker)); await session.EnsureHostStartedAsync(new RHostStartupInfo(), null, 1000); var switch1Task = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchToTheSameBroker) + "1"); var switch2Task = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchToTheSameBroker) + "1"); await ParallelTools.WhenAll(30000, switch1Task, switch2Task); switch1Task.Status.Should().Be(TaskStatus.RanToCompletion); switch2Task.Status.Should().Be(TaskStatus.RanToCompletion); } }
public async Task ConnectWhenSwitching_SwitchFailed() { using (var sessionProvider = new RSessionProvider(_services)) { await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(ConnectWhenSwitching_SwitchFailed)); var switchTask = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(ConnectWhenSwitching_SwitchFailed) + "1", BrokerConnectionInfo.Create(null, "JHFFR", @"\\JHF\F\R")); await Task.Yield(); var session = sessionProvider.GetOrCreate(nameof(ConnectWhenSwitching_SwitchFailed)); var startHostTask = session.EnsureHostStartedAsync(new RHostStartupInfo(), null, 1000); await ParallelTools.WhenAll(30000, switchTask, startHostTask); startHostTask.Should().BeRanToCompletion(); switchTask.Should().BeRanToCompletion(); switchTask.Result.Should().BeFalse(); } }
public async Task SwitchMultipleSessions() { using (var sessionProvider = new RSessionProvider(_services)) { await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchMultipleSessions)).Should().BeCompletedAsync(); var sessions = new IRSession[4]; for (var i = 0; i < sessions.Length; i++) { sessions[i] = sessionProvider.GetOrCreate(nameof(SwitchMultipleSessions) + i); sessions[i].RestartOnBrokerSwitch = true; } await ParallelTools.WhenAll(30000, sessions.Select((s, i) => s.EnsureHostStartedAsync(new RHostStartupInfo(), null, 30000)).ToArray()); await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchMultipleSessions) + "1").Should().BeCompletedAsync(); sessions.Should().OnlyContain(s => s.IsHostRunning); } }
public async Task SwitchToInvalid() { using (var sessionProvider = new RSessionProvider(_coreServices)) { var session = sessionProvider.GetOrCreate(nameof(SwitchToInvalid)); await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchToInvalid)); await session.EnsureHostStartedAsync(new RHostStartupInfo(), null, 1000); var switch1Task = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchToInvalid) + "1", BrokerConnectionInfo.Create("JHFFR", @"\\JHF\F\R")); await Task.Yield(); var switch2Task = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchToInvalid) + "2"); await ParallelTools.WhenAll(30000, switch1Task, switch2Task); switch1Task.Should().BeRanToCompletion(); switch1Task.Result.Should().BeFalse(); switch2Task.Should().BeRanToCompletion(); switch2Task.Result.Should().BeTrue(); } }
public async Task SwitchWhenConnecting() { using (var sessionProvider = new RSessionProvider(_coreServices)) { var session = sessionProvider.GetOrCreate(nameof(SwitchWhenConnecting)); session.RestartOnBrokerSwitch = true; await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchWhenConnecting)); var startHostTask = session.EnsureHostStartedAsync(new RHostStartupInfo(), null, 1000); await Task.Yield(); var switch1Task = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchWhenConnecting) + "1"); var switch2Task = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchWhenConnecting) + "2"); await ParallelTools.WhenAll(startHostTask, switch1Task, switch2Task); switch1Task.Status.Should().Be(TaskStatus.RanToCompletion); switch2Task.Status.Should().Be(TaskStatus.RanToCompletion); startHostTask.Status.Should().Be(TaskStatus.RanToCompletion); await session.HostStarted.Should().BeCompletedAsync(); } }