MbUnit Icarus self-destructs on this test
Asked Answered
C

1

6

I'm trying to test a multi-threaded IO class using MbUnit. My goal is to have the test fixture constructor execute 3 times, once for each row on the class. Then, for each instance, execute the tests multiple times on parallell threads.

However, Icarus blows up with an 'index out of range' on TaskRunner. I can't get the full stack, it spawns message boxes too fast.

What am I doing wrong, or is this a bug 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);
        }
    }
}
Calie answered 11/4, 2011 at 23:29 Comment(0)
T
1

I wont answer direct question about bug but I think following steps will help find the error and not get lost in popping message boxes

  • decrease numbers of totalfiles , subfolders to much lower values to see if error persists in 2 or even 1 file counts

    • your tests code isn't super easy, as it should be, write tests for tests so you know they are running correct, maybe those random nexts are the problem, maybe something else, tests should be easy.

    • figure out what test breaks the system, your code contains 3 tests, and constructor, comment two other tests and see which one produces error

    • your threaded repeat 150 looks pretty sick, maybe try smaller number like 2 or 3 if error is basic even 2 threads might break, if you run 150 threads I can understand your trouble with message boxes

    • add logging and try catch - catch that index exception and log your class state carefully, after inspecting it I think youll see problem much more clearly.

Right now you cant figure out the problem I think, you got too many variables , not to mention you didnt provide code for your Cache class which might contain some simple error that is causing it, before MBunit features even begin to show up.

Turbid answered 21/5, 2011 at 23:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.