コード例 #1
0
        internal static void TestFollowerConcurrency(AbstractClient C)
        {
            const int Iterations = 10000;

            // Two threads racing each other adding and removing followers
            new Thread(new ThreadStart(() =>
            {
                for (int i = 0; i < Iterations; i++)
                {
                    C.AddFollower(R.Next());
                }
            })).Start();
            new Thread(new ThreadStart(() =>
            {
                for (int i = 0; i < Iterations; i++)
                {
                    var List = C.GetCurrentFollowers();
                    if (List.Count > 0)
                    {
                        C.RemoveFollower(List[R.Next(List.Count)]);
                    }
                    else
                    {
                        // Remove non-existant followers should work too!
                        C.RemoveFollower(R.Next());
                    }
                }
            })).Start();
            // No exception should be thrown
            Assert.Pass();
        }
コード例 #2
0
 internal static void TestFollowerConcurrency(AbstractClient C)
 {
     const int Iterations = 10000;
     // Two threads racing each other adding and removing followers
     new Thread(new ThreadStart(() =>
     {
         for (int i = 0; i < Iterations; i++)
         {
             C.AddFollower(R.Next());
         }
     })).Start();
     new Thread(new ThreadStart(() =>
     {
         for (int i = 0; i < Iterations; i++)
         {
             var List = C.GetCurrentFollowers();
             if (List.Count > 0)
             {
                 C.RemoveFollower(List[R.Next(List.Count)]);
             }
             else
             {
                 // Remove non-existant followers should work too!
                 C.RemoveFollower(R.Next());
             }
         }
     })).Start();
     // No exception should be thrown
     Assert.Pass();
 }
コード例 #3
0
        // Shared with Connected client too
        internal static void TestFollowers(AbstractClient C)
        {
            C.AddFollower(1);
            C.AddFollower(2);
            // Double add
            C.AddFollower(2);
            C.AddFollower(3);
            var Followers = C.GetCurrentFollowers();

            Assert.That(Followers.Count == 3, "Dummy client's follower adding error! A follower with the same ID can only be added once!");
            Assert.That(Followers.Contains(2), "Dummy client's follower adding error!");
            Assert.False(Followers.Contains(4), "Dummy client's follower checking error!");

            // External modification must not affect internal operation
            Followers.Add(5);
            Assert.False(C.GetCurrentFollowers().Contains(5), "Dummy client's GetCurrentFollowers should not return the internal follower list!");
        }
コード例 #4
0
        // Shared with Connected client too
        internal static void TestFollowers(AbstractClient C)
        {
            C.AddFollower(1);
            C.AddFollower(2);
            // Double add
            C.AddFollower(2);
            C.AddFollower(3);
            var Followers = C.GetCurrentFollowers();
            Assert.That(Followers.Count == 3, "Dummy client's follower adding error! A follower with the same ID can only be added once!");
            Assert.That(Followers.Contains(2), "Dummy client's follower adding error!");
            Assert.False(Followers.Contains(4), "Dummy client's follower checking error!");

            // External modification must not affect internal operation
            Followers.Add(5);
            Assert.False(C.GetCurrentFollowers().Contains(5), "Dummy client's GetCurrentFollowers should not return the internal follower list!");
        }