2011-04-11 6 views
6

MbUnit을 사용하여 멀티 스레드 IO 클래스를 테스트하려고합니다. 내 목표는 테스트 고정물 생성자가 클래스의 각 행에 대해 3 번 실행되도록하는 것입니다. 그런 다음 각 인스턴스에 대해 병렬 스레드에서 여러 번 테스트를 실행하십시오.이 테스트에서 MbUnit Icarus가 자멸합니다.

그러나 Icarus는 TaskRunner에서 '범위를 벗어난 색인'으로 폭발합니다. 전체 스택을 가져올 수 없으며 너무 빠르게 메시지 상자를 생성합니다.

무엇이 잘못 되었나요? 아니면 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); 
     } 
    } 
} 

답변

1

나는 버그에 대한 직접적인 질문에 대답 실 거예요하지만 오류를 발견하지 도움이 될 것입니다 다음 단계 totalfiles의

  • 감소 번호, 하위 폴더 훨씬 낮은 값으로 터지는 메시지 상자에서 분실 생각 오류가 2 년 지속 또는 1 파일이

    • 당신의 테스트 C를 계산하는 경우 에 참조 ODE는 그것이 있어야로, 테스트 에 대한 쓰기 시험은 그래서 당신은 그들이 어쩌면 그 임의 nexts 어쩌면 뭔가 다른 문제이며, 가 올바른 실행을 알고, 슈퍼 쉬운 일이 아닙니다 이며, 시험은 쉽게해야합니다.

    • 그림 밖으로 어떤 테스트는 두 개의 다른 테스트를 언급 한이 오류

    • 150 꽤 아픈 보이는 당신의 스레드 반복을 생산하는 참조 시스템, 코드가 3 개 테스트, 와 생성자를 포함 나누기 오류가 기본 도 2 개 스레드가 깰 수 있다면 당신 실행 150 개 스레드가 I 메시지 상자 당신의 문제를 이해할 수 있다면 아마, 2, 3 등의 작은 수를 시도

    • 로깅을 추가하고 캐치를 시도하십시오. 해당 인덱스 예외를 확인하고 클래스 상태를 자세히 기록하십시오. 검사를 마치면 문제를 훨씬 더 명확하게 볼 수 있습니다.

지금 당신은 당신이 너무 많은 변수를 가지고, 내가 생각하는 문제를 파악하지 못할, 전에, 당신이 그것을 일으키는 몇 가지 간단한 오류를 포함 할 수 있습니다 귀하의 캐시 클래스에 대한 코드를 제공 didnt는 말할 것도없고 MB 단위 기능도 표시되기 시작합니다.

관련 문제