MbUnit Icarus will self-destruct on this test

I am trying to test a multi-threaded I / O class using MbUnit. My goal is for the test fixture constructor to execute 3 times, once for each row in the class. Then, for each instance, run tests on parallel threads several times.

However, Icarus explodes an “out of range index” on TaskRunner. I cannot get a full stack, it spawns message windows too quickly.

What am I doing wrong, or is it an error in MbUnit / Gallio?

using System; using System.Collections.Generic; using System.Text; using Gallio.Framework; using MbUnit.Framework; using MbUnit.Framework.ContractVerifiers; using System.IO; namespace ImageResizer.Plugins.DiskCache.Tests { [TestFixture] [Row(0,50,false)] [Row(0,50,true)] [Row(8000,100,true)] public class CustomDiskCacheTest { public CustomDiskCacheTest(int subfolders, int totalFiles, bool hashModifiedDate) { char c = System.IO.Path.DirectorySeparatorChar; string folder = System.IO.Path.GetTempPath().TrimEnd(c) + c + System.IO.Path.GetRandomFileName(); cache = new CustomDiskCache(folder,subfolders,hashModifiedDate); this.quantity = totalFiles; for (int i = 0; i < quantity;i++){ cache.GetCachedFile(i.ToString(),"test",delegate(Stream s){ s.WriteByte(32); //Just one space },defaultDate, 10); } } int quantity; CustomDiskCache cache = null; DateTime defaultDate = new DateTime(2011, 1, 1); [ThreadedRepeat(150)] [Test(Order=1)] public void TestAccess() { CacheResult r = cache.GetCachedFile(new Random().Next(0, quantity).ToString(), "test", delegate(Stream s) { Assert.Fail("No files have been modified, this should not execute"); }, defaultDate, 100); Assert.IsTrue(System.IO.File.Exists(r.PhysicalPath)); Assert.IsTrue(r.Result == CacheQueryResult.Hit); } volatile int seed = 0; [Test (Order=2)] [ThreadedRepeat(20)] public void TestUpdate() { //try to get a unique date time value DateTime newTime = DateTime.UtcNow.AddDays(seed++); CacheResult r = cache.GetCachedFile(new Random().Next(0, quantity).ToString(), "test", delegate(Stream s) { s.WriteByte(32); //Just one space }, newTime, 100); Assert.AreEqual<DateTime>(newTime, System.IO.File.GetLastWriteTimeUtc(r.PhysicalPath)); Assert.IsTrue(r.Result == CacheQueryResult.Miss); } [Test(Order=3)] public void TestClear() { System.IO.Directory.Delete(cache.PhysicalCachePath, true); } } } 
+6
source share
1 answer

I will not answer the direct question about the error, but I think that the following steps will help find the error and not get lost in the message boxes that appear

  • reduce the number of shared files, subfolders to lower values, see if the error persists in 2 or even 1 number of files

    • your test code is not super easy, as it should be, write tests for tests so you know that they work correctly, maybe a random problem, maybe something else, the tests should be easy.

    • find out which test the system violates, your code contains 3 tests, and the constructor, comment on the other two tests and see which one is Error

    • repeating repeat 150 looks pretty sick, maybe try a smaller number equal to 2 or 3, if the error is the main one even 2 threads may break if you run 150 threads that I can understand your problems with message boxes

    • add a log and try to catch this index exception and write down your class carefully, after checking it, I think you will see the problem much more clearly.

You cannot understand the problem right now, I think you have too many variables, not to mention the fact that you did not specify the code for your Cache class, which may contain some simple error causing it before the MBunit functions even start appearing .

+1
source

Source: https://habr.com/ru/post/885688/


All Articles