Exemple #1
0
        public void TestFailureDetection4()
        {
            using (var handle = new ManualResetEvent(false))
            {
                Resolution?resolution = null;

                var handler = new Mock <IFailureHandler>();
                handler.Setup(x => x.OnResolutionFinished(It.IsAny <Failure>(), It.IsAny <Decision>(), It.IsAny <Resolution>()))
                .Callback((Failure f, Decision d, Resolution r) =>
                {
                    resolution = r;
                    handle.Set();
                });

                using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(failureHandler: handler.Object))
                {
                    silo.Start();
                    IVoidMethodNoParameters proxy = silo.CreateGrain <IVoidMethodNoParameters, CausesAccessViolation>();

                    new Action(proxy.Do).ShouldThrow <ConnectionLostException>();

                    handle.WaitOne(TimeSpan.FromSeconds(5)).Should().BeTrue();
                    resolution.Should().Be(Resolution.Stopped);
                }
            }
        }
        public void TestFailureDetection9()
        {
            using (var handle = new ManualResetEvent(false))
            {
                Resolution?resolution = null;

                var handler = new Mock <IFailureHandler>();
                handler.Setup(x => x.OnResolutionFinished(It.IsAny <Failure>(), It.IsAny <Decision>(), It.IsAny <Resolution>()))
                .Callback((Failure f, Decision d, Resolution r) =>
                {
                    resolution = r;
                    handle.Set();
                });

                var settings = new PostMortemSettings
                {
                    CollectMinidumps     = true,
                    SuppressErrorWindows = true,
                    HandleCrtPureVirtualFunctionCalls = true,
#if DEBUG
                    RuntimeVersions = CRuntimeVersions._110 | CRuntimeVersions.Debug,
#else
                    RuntimeVersions = CRuntimeVersions._110 | CRuntimeVersions.Release,
#endif
                    NumMinidumpsRetained = 1,
                    MinidumpFolder       = Path.Combine(Path.GetTempPath(), "SharpRemote", "dumps"),
                    MinidumpName         = "Host"
                };

                if (Directory.Exists(settings.MinidumpFolder))
                {
                    Directory.Delete(settings.MinidumpFolder, true);
                }

                using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(postMortemSettings: settings))
                {
                    silo.Start();
                    IVoidMethodNoParameters proxy = silo.CreateGrain <IVoidMethodNoParameters, CausesPureVirtualFunctionCall>();

                    DateTime beforeFailure = DateTime.Now;
                    new Action(proxy.Do).ShouldThrow <ConnectionLostException>();
                    DateTime afterFailure = DateTime.Now;


                    // Not only should a failure have been detected, but a dump should've been created and stored
                    // on disk..

                    List <string> files = Directory.EnumerateFiles(settings.MinidumpFolder).ToList();
                    files.Count.Should().Be(1, "Because exactly one minidump should've been created");

                    var file = new FileInfo(files[0]);
                    file.Name.Should().EndWith(".dmp");
                    file.LastWriteTime.Should().BeOnOrAfter(beforeFailure);
                    file.LastWriteTime.Should().BeOnOrBefore(afterFailure);
                }
            }
        }
Exemple #3
0
        public void TestRestart4()
        {
            IGetInt32Property       someGrain = null;
            IVoidMethodNoParameters killer    = null;

            _silo.OnHostStarted += () =>
            {
                someGrain = _silo.CreateGrain <IGetInt32Property, ReturnsPid>();
                killer    = _silo.CreateGrain <IVoidMethodNoParameters, DeadlocksProcess>();
                _startHandle.Set();
            };
            _silo.Start();
            _startHandle.Reset();

            new Action(() => killer.Do()).ShouldThrow <ConnectionLostException>();
            _startHandle.WaitOne(TimeSpan.FromSeconds(10)).Should().BeTrue("because the silo should've restarted the host process automatically");
            var newPid = _silo.HostProcessId;

            someGrain.Value.Should().Be(newPid);
        }
        public void TestFailureDetection8()
        {
            using (var handle = new ManualResetEvent(false))
            {
                Resolution?resolution = null;

                var handler = new Mock <IFailureHandler>();
                handler.Setup(x => x.OnResolutionFinished(It.IsAny <Failure>(), It.IsAny <Decision>(), It.IsAny <Resolution>()))
                .Callback((Failure f, Decision d, Resolution r) =>
                {
                    resolution = r;
                    handle.Set();
                });

                var settings = new PostMortemSettings
                {
                    SuppressErrorWindows = true,
                    HandleCrtPureVirtualFunctionCalls = true,
#if DEBUG
                    RuntimeVersions = CRuntimeVersions._110 | CRuntimeVersions.Debug,
#else
                    RuntimeVersions = CRuntimeVersions._110 | CRuntimeVersions.Release,
#endif
                };

                using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(postMortemSettings: settings))
                {
                    silo.Start();
                    IVoidMethodNoParameters proxy = silo.CreateGrain <IVoidMethodNoParameters, CausesPureVirtualFunctionCall>();

                    Task task = Task.Factory.StartNew(() => { new Action(proxy.Do).ShouldThrow <ConnectionLostException>(); });
                    //task.Wait(TimeSpan.FromSeconds(5)).Should().BeTrue();
                    task.Wait();

                    handle.WaitOne(TimeSpan.FromSeconds(5)).Should().BeTrue();
                    resolution.Should().Be(Resolution.Stopped);
                }
            }
        }
        public void TestFailureDetection5()
        {
            var settings = new PostMortemSettings
            {
                CollectMinidumps       = true,
                SuppressErrorWindows   = true,
                HandleAccessViolations = true,
                NumMinidumpsRetained   = 1,
                MinidumpFolder         = Path.Combine(Path.GetTempPath(), "SharpRemote", "dumps"),
                MinidumpName           = "Host"
            };

            if (Directory.Exists(settings.MinidumpFolder))
            {
                Directory.Delete(settings.MinidumpFolder, true);
            }

            using (var silo = new SharpRemote.Hosting.OutOfProcessSilo(postMortemSettings: settings))
            {
                silo.Start();
                IVoidMethodNoParameters proxy = silo.CreateGrain <IVoidMethodNoParameters, CausesAccessViolation>();

                DateTime beforeFailure = DateTime.Now;
                new Action(proxy.Do).ShouldThrow <ConnectionLostException>();
                DateTime afterFailure = DateTime.Now;

                // Not only should a failure have been detected, but a dump should've been created and stored
                // on disk..

                List <string> files = Directory.EnumerateFiles(settings.MinidumpFolder).ToList();
                files.Count.Should().Be(1, "Because exactly one minidump should've been created");

                var file = new FileInfo(files[0]);
                file.Name.Should().EndWith(".dmp");
                file.LastWriteTime.Should().BeOnOrAfter(beforeFailure);
                file.LastWriteTime.Should().BeOnOrBefore(afterFailure);
            }
        }