MultiThreadingTest.cs 1.56 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Svg.Exceptions;
using System;
using System.Diagnostics;
using System.Threading.Tasks;

namespace Svg.UnitTests
{

    [TestClass]
    public class MultiThreadingTest : SvgTestHelper
12
13
    {
		protected override string TestResource { get { return GetFullResourceString("Issue_Threading.TestFile.svg"); } }
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
		protected override int ExpectedSize { get { return 100; } }

        private void LoadFile()
        {
            LoadSvg(GetXMLDocFromResource());
        }

        
        [TestMethod]
        public void LoadSVGThreading_SingleThread_YieldsNoError()
        {
            LoadFile();
        }


        [TestMethod]
        public void LoadSVGThreading_MultiThread_YieldsNoErrorWhileInBounds()
        {
            Parallel.For(0, 10, (x) =>
            {
                LoadFile();
            });
            Trace.WriteLine("Done");
        }


        [TestMethod]
        public void LoadSVGThreading_MultiThread_GivesMemoryExceptionOnTooManyParallelTest()
42
43
44
45
        {
			try
			{
				Parallel.For(0, 100, (x) =>
46
				{
47
48
49
50
51
52
53
54
55
					LoadFile();
				});
			}
			catch (AggregateException ex)
			{
				//We expect an SVG Memory Exception to be thrown, thats okay, otherwise fail
				if (!(ex.InnerException is SvgMemoryException))
				{
					throw ex.InnerException;
56
57
				}
			}
58
			Assert.Inconclusive("This test was expected to throw an SVGMemoryException, however this is higly dependent on the file and machine under test. This is not a fail reason.");
59
60
61
        }
    }
}