public virtual void TestRandom()
        {
            DocumentsWriterStallControl ctrl = new DocumentsWriterStallControl();

            ctrl.UpdateStalled(false);

            ThreadClass[] stallThreads = new ThreadClass[AtLeast(3)];
            for (int i = 0; i < stallThreads.Length; i++)
            {
                int stallProbability = 1 + Random().Next(10);
                stallThreads[i] = new ThreadAnonymousInnerClassHelper(this, ctrl, stallProbability);
            }
            Start(stallThreads);
            long time = DateTime.Now.Millisecond;

            /*
             * use a 100 sec timeout to make sure we not hang forever. join will fail in
             * that case
             */
            while ((DateTime.Now.Millisecond - time) < 100 * 1000 && !Terminated(stallThreads))
            {
                ctrl.UpdateStalled(false);
                if (Random().NextBoolean())
                {
                    Thread.@Yield();
                }
                else
                {
                    Thread.Sleep(1);
                }
            }
            Join(stallThreads);
        }
            public override void Run()
            {
                bool done = false;

                while (!done)
                {
                    for (int i = 0; i < 100; i++)
                    {
                        try
                        {
                            FinalWriter.AddDocument(Doc);
                        }
                        catch (AlreadyClosedException e)
                        {
                            done = true;
                            break;
                        }
                        catch (System.NullReferenceException e)
                        {
                            done = true;
                            break;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.StackTrace);
                            Failure.Add(e);
                            done = true;
                            break;
                        }
                    }
                    Thread.@Yield();
                }
            }
 /// <summary>
 /// Waits for all incoming threads to be in wait()
 ///  methods.
 /// </summary>
 public static void AwaitState(ThreadState state, params ThreadClass[] threads)
 {
     while (true)
     {
         bool done = true;
         foreach (ThreadClass thread in threads)
         {
             if (thread.State != state)
             {
                 done = false;
                 break;
             }
         }
         if (done)
         {
             return;
         }
         if (Random().NextBoolean())
         {
             Thread.@Yield();
         }
         else
         {
             Thread.Sleep(1);
         }
     }
 }
Exemple #4
0
        public override void WriteBytes(byte[] b, int offset, int len)
        {
            CheckCrashed();
            CheckDiskFull(b, offset, null, len);

            if (Dir.RandomState.Next(200) == 0)
            {
                int half = len / 2;
                @delegate.WriteBytes(b, offset, half);
                Thread.@Yield();
                @delegate.WriteBytes(b, offset + half, len - half);
            }
            else
            {
                @delegate.WriteBytes(b, offset, len);
            }

            Dir.MaybeThrowDeterministicException();

            if (First)
            {
                // Maybe throw random exception; only do this on first
                // write to a new file:
                First = false;
                Dir.MaybeThrowIOException(Name);
            }
        }
Exemple #5
0
 public virtual void Apply(string message)
 {
     if (Random.Next(4) == 2)
     {
         Thread.@Yield();
     }
 }
 public void Apply(string name)
 {
     //      if (name.equals("startCommit")) {
     if (Random().Next(4) == 2)
     {
         Thread.@Yield();
     }
 }
Exemple #7
0
        public virtual void TestThreadLeak()
        {
            ThreadClass t = new ThreadAnonymousInnerClassHelper(this);

            t.Start();

            while (!t.IsAlive)
            {
                Thread.@Yield();
            }

            // once alive, leave it to run outside of the test scope.
        }
 public override void Run()
 {
     try
     {
         while (!Stop.Get())
         {
             int internalIters = Release && Random().NextBoolean() ? AtLeast(5) : 1;
             for (int i = 0; i < internalIters; i++)
             {
                 Ctrl.UpdateStalled(Random().NextBoolean());
             }
             if (CheckPoint.Get())
             {
                 Sync.UpdateJoin.countDown();
                 try
                 {
                     Assert.IsTrue(Sync.@await());
                 }
                 catch (ThreadInterruptedException e)
                 {
                     Console.WriteLine("[Updater] got interrupted - wait count: " + Sync.Waiter.Remaining);
                     throw new ThreadInterruptedException(e);
                 }
                 Sync.LeftCheckpoint.countDown();
             }
             if (Random().NextBoolean())
             {
                 Thread.@Yield();
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         Console.Write(e.StackTrace);
         Exceptions.Add(e);
     }
     Sync.UpdateJoin.countDown();
 }