public void MemoryLimitWorks() { // Check, if current OS is Linux. Skip.IfNot(Environment.OSVersion.Platform == PlatformID.Unix); var timeout = TimeSpan.FromSeconds(10); var memoryLimitMegabyte = 1; var tunerConfig = new AlgorithmTunerConfiguration.AlgorithmTunerConfigurationBuilder().SetCpuTimeout(timeout).Build(1); var timer = new Stopwatch(); timer.Start(); var lingelingRunner = new LingelingRunner( new Dictionary <string, IAllele>(), LingelingRunnerTests.PathToExecutable, tunerConfig, memoryLimitMegabyte); var runner = lingelingRunner.Run( new InstanceSeedFile(LingelingRunnerTests.PathToTestInstance, LingelingRunnerTests.TestInstanceSeed), this._cancellationTokenSource.Token); runner.Wait(); timer.Stop(); runner.Result.ShouldNotBeNull(); runner.Result.IsCancelled.ShouldBeTrue(); runner.Result.Runtime.ShouldBe(timeout); timer.Elapsed.ShouldBeLessThan(timeout); }
public void CancellationWorks() { // Check, if current OS is Linux. Skip.IfNot(Environment.OSVersion.Platform == PlatformID.Unix); var timeout = TimeSpan.FromSeconds(30); var memoryLimitMegabyte = 4000; var tunerConfig = new AlgorithmTunerConfiguration.AlgorithmTunerConfigurationBuilder().SetCpuTimeout(timeout).Build(1); var timer = new Stopwatch(); timer.Start(); // Run Lingeling. var lingelingRunner = new LingelingRunner( new Dictionary <string, IAllele>(), LingelingRunnerTests.PathToExecutable, tunerConfig, memoryLimitMegabyte); var runner = lingelingRunner.Run( new InstanceSeedFile(LingelingRunnerTests.PathToTestInstance, LingelingRunnerTests.TestInstanceSeed), this._cancellationTokenSource.Token); // Cancel task and expect it to be cancelled. try { Thread.Sleep(100); this._cancellationTokenSource.Cancel(); runner.Wait(); Assert.True(false, "Expected a task cancelled exception."); } catch (AggregateException aggregateException) { timer.Stop(); aggregateException.InnerExceptions.Count.ShouldBe(1); var innerException = aggregateException.InnerExceptions.Single(); innerException.ShouldBeOfType <TaskCanceledException>(); runner.IsCanceled.ShouldBeTrue(); timer.Elapsed.ShouldBeLessThan(TimeSpan.FromSeconds(1)); } catch (Exception) { Assert.True(false, "Expected a task cancelled exception."); } }