Ejemplo n.º 1
0
        public void VersionsTestCase()
        {
            ThisConfiguration = "Release";
            //Console.WriteLine($"Test {thisConfiguration} configuration on the {thisFramework} framework.");

            // Delete previously existing files
            Util.CleanPaths();
            // Many iterations of assembly loading
            for (int i = 0; i < 10; ++i)
            {
                var assembly1 = new TestAssembly(ThisPath, "1-0-0", ThisConfiguration, TargetFramework);
                var assembly2 = new TestAssembly(ThisPath, "2-0-0", ThisConfiguration, TargetFramework);

                var r1 = assembly1.Invoke(6, 7);
                var r2 = assembly2.Invoke(6, 7);

                Assert.AreEqual(13, r1, $"Assembly V{assembly1.Version} result mismatch");
                Assert.AreEqual(42, r2, $"Assembly V{assembly2.Version} result mismatch");
            }
        }
Ejemplo n.º 2
0
        public void TestMultithreading()
        {
            int remaining = numThreads, unsuccesful = numThreads;

            Util.CleanPaths();
            for (int i = 0; i < numThreads; ++i)
            {
                (new Thread((x) =>
                {
                    int j = (int)x;
                    try
                    {
                        Thread.Sleep(500);
                        var assembly1 = new TestAssembly(ThisPath, 0 == (j & 1) ? "1-0-0" : "2-0-0", ThisConfiguration, TargetFramework);
                        assembly1.Invoke(123, 12345);

                        Console.WriteLine($"Thread {j} done");
                        Interlocked.Decrement(ref unsuccesful);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.StackTrace);
                    }

                    Interlocked.Decrement(ref remaining);
                })).Start(i);
            }

            for (int i = 0; i < (numThreads * msPerThread / 20); ++i)
            {
                if (0 == Interlocked.Add(ref remaining, 0))
                {
                    Assert.AreEqual(0, Interlocked.Add(ref unsuccesful, 0), $"{unsuccesful} threads threw an exception");
                    return;                     // Ok
                }

                Thread.Sleep(20);
            }

            Assert.Fail($"{remaining} threads failed to finish before timeout, {unsuccesful} threw exception");
        }