示例#1
0
        public void ProcessLimiter_AutoTerminate()
        {
            // Run the:
            //
            //      VEGOMATIC MEMORY ALLOC 500
            //
            // command to allocate 500MB of memory and then verify that
            // a process limiter will automatically terminate it.

            Process process = null;

            try
            {
                ProcessLimiter.PollInterval     = TimeSpan.FromSeconds(1);
                ProcessLimiter.LogFlushInterval = TimeSpan.FromSeconds(1);

                process = Process.Start("vegomatic", "memory alloc 500");
                var limits = new ProcessLimits(process)
                {
                    PagedMemorySize = 250 * 1024 * 1024
                };

                ProcessLimiter.Add(limits);

                Helper.WaitFor(() => process.HasExited, TimeSpan.FromSeconds(30));
            }
            finally
            {
                ProcessLimiter.Reset();

                if (process != null && !process.HasExited)
                {
                    process.Kill();
                }
            }
        }
示例#2
0
        public void ProcessLimiter_Notify()
        {
            // Run the:
            //
            //      VEGOMATIC MEMORY ALLOC 500
            //
            // command to allocate 500MB of memory and then configure a
            // process limit of 250MB and verify that we get a notification.

            Process process = null;

            try
            {
                ProcessLimiter.PollInterval = TimeSpan.FromSeconds(1);

                var notified = false;
                process = Process.Start("vegomatic", "memory alloc 500");
                var limits = new ProcessLimits(process, (l, m) => { notified = true; })
                {
                    PagedMemorySize = 250 * 1024 * 1024
                };

                ProcessLimiter.Add(limits);

                Helper.WaitFor(() => notified, TimeSpan.FromSeconds(30));
            }
            finally
            {
                ProcessLimiter.Reset();

                if (process != null && !process.HasExited)
                {
                    process.Kill();
                }
            }
        }