Пример #1
0
        public async Task RefreshEvent_DoesNothing_NoEvent()
        {
            var rand  = new Random(1234);
            var queue = new TestQueue();

            for (ulong i = 0; i < 1000; i++)
            {
                var nextRole = rand.Next(0, 3) switch
                {
                    0 => FFXIVRole.DPS,
                    1 => FFXIVRole.Healer,
                    2 => FFXIVRole.Tank,
                    _ => throw new NotImplementedException(),
                };
                queue.Enqueue(i, nextRole, null);
                await Task.Delay(rand.Next(1, 20));
            }
            queue.RefreshEvent(EventId);
            var timestamps = queue.GetAllSlots()
                             .ToList();
            var firstTimestamp = timestamps.First().QueueTime;

            foreach (var slot in timestamps.Skip(1))
            {
                Assert.AreNotEqual(firstTimestamp, slot.QueueTime);
            }
        }
Пример #2
0
        public void ExpireEvent_DoesNothing_NoEvent()
        {
            var rand  = new Random(1234);
            var queue = new TestQueue();

            for (ulong i = 0; i < 1000; i++)
            {
                var nextRole = rand.Next(0, 3) switch
                {
                    0 => FFXIVRole.DPS,
                    1 => FFXIVRole.Healer,
                    2 => FFXIVRole.Tank,
                    _ => throw new NotImplementedException(),
                };
                queue.Enqueue(i, nextRole, null);
            }

            queue.ExpireEvent(null);

            var slots = queue.GetAllSlots();

            foreach (var slot in slots)
            {
                Assert.That(string.IsNullOrEmpty(slot.EventId));
            }
        }
Пример #3
0
        public void Dequeue_IsThreadSafe()
        {
            var rand   = new Random(1234);
            var queue  = new TestQueue();
            var counts = new Dictionary <FFXIVRole, int>
            {
                { FFXIVRole.DPS, 0 },
                { FFXIVRole.Healer, 0 },
                { FFXIVRole.Tank, 0 },
            };

            for (ulong i = 0; i < 1000; i++)
            {
                var curI     = i;
                var nextRole = rand.Next(0, 3) switch
                {
                    0 => FFXIVRole.DPS,
                    1 => FFXIVRole.Healer,
                    2 => FFXIVRole.Tank,
                    _ => throw new NotImplementedException(),
                };
                counts[nextRole]++;
                queue.Enqueue(curI, nextRole, "");
            }

            var threads = new List <Thread>();
            var outList = new SynchronizedCollection <ulong>();
            var roles   = new[] { FFXIVRole.DPS, FFXIVRole.Healer, FFXIVRole.Tank };

            foreach (var role in roles)
            {
                for (var i = 0; i < counts[role]; i++)
                {
                    var thread = new Thread(() =>
                    {
                        Thread.Sleep(rand.Next(0, 1001));
                        var id = queue.Dequeue(role, null);
                        if (id != null)
                        {
                            outList.Add(id.Value);
                        }
                    });
                    thread.Start();
                    threads.Add(thread);
                }
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }

            var slots = queue.GetAllSlots().ToList();

            Assert.That(!slots.Any());
            Assert.That(outList.Count == 1000);
        }
Пример #4
0
        public void DropUnconfirmed_DoesNothing_NoEvent()
        {
            var queue = new TestQueue();

            queue.Enqueue(UserId, FFXIVRole.DPS, null);
            queue.Enqueue(0, FFXIVRole.Tank, "");
            queue.Enqueue(1, FFXIVRole.Healer, null);
            queue.Enqueue(2, FFXIVRole.Healer, null);
            queue.Enqueue(3, FFXIVRole.Tank, null);
            queue.DropUnconfirmed(null);
            Assert.IsNotEmpty(queue.GetAllSlots());
        }
Пример #5
0
        public void DropUnconfirmed_Works_Event()
        {
            var queue = new TestQueue();

            queue.Enqueue(UserId, FFXIVRole.DPS, EventId);
            queue.Enqueue(0, FFXIVRole.Tank, EventId);
            queue.Enqueue(1, FFXIVRole.Healer, EventId);
            queue.Enqueue(2, FFXIVRole.Healer, EventId);
            queue.Enqueue(3, FFXIVRole.Tank, EventId);
            queue.DropUnconfirmed(EventId);
            Assert.IsEmpty(queue.GetAllSlots());
        }
Пример #6
0
        public async Task Refresh_Works_NoEvent(FFXIVRole role)
        {
            var queue        = new TestQueue();
            var enqueuedSlot = new QueueSlot(UserId, "", new List <ulong>())
            {
                QueueTime = DateTime.UtcNow.AddHours(-4).AddMinutes(-45),
            };

            queue.AddSlot(enqueuedSlot, role);
            await Task.Delay(1000);

            var now = DateTime.UtcNow;

            queue.Refresh(UserId);
            var dequeuedSlot = queue.GetAllSlots().First();

            Assert.AreEqual(now.Hour, dequeuedSlot.QueueTime.Hour);
            Assert.AreEqual(now.Minute, dequeuedSlot.QueueTime.Minute);
        }
Пример #7
0
        public void Enqueue_IsThreadSafe()
        {
            var rand    = new Random(1234);
            var queue   = new TestQueue();
            var threads = new List <Thread>();

            for (ulong i = 0; i < 1000; i++)
            {
                var curI     = i;
                var nextRole = rand.Next(0, 3) switch
                {
                    0 => FFXIVRole.DPS,
                    1 => FFXIVRole.Healer,
                    2 => FFXIVRole.Tank,
                    _ => throw new NotImplementedException(),
                };
                var thread = new Thread(() =>
                {
                    Thread.Sleep(rand.Next(0, 1001));
                    queue.Enqueue(curI, nextRole, "");
                });
                thread.Start();
                threads.Add(thread);
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }

            var slots = queue.GetAllSlots().ToList();

            slots.Sort((a, b) => (int)a.Id - (int)b.Id);
            for (ulong i = 0; i < 1000; i++)
            {
                Assert.That(slots[(int)i].Id == i);
            }
        }
Пример #8
0
        public void ExpireEvent_Works_Event()
        {
            var rand  = new Random(1234);
            var queue = new TestQueue();

            for (ulong i = 0; i < 1000; i++)
            {
                var nextRole = rand.Next(0, 3) switch
                {
                    0 => FFXIVRole.DPS,
                    1 => FFXIVRole.Healer,
                    2 => FFXIVRole.Tank,
                    _ => throw new NotImplementedException(),
                };
                queue.Enqueue(i, nextRole, EventId);
            }

            queue.ExpireEvent(EventId);

            var slots = queue.GetAllSlots();

            Assert.That(!slots.Any());
        }
Пример #9
0
        public void QueryTimeout_NoIncludeEvents_Works()
        {
            var rand   = new Random(1234);
            var queue  = new TestQueue();
            var counts = new Dictionary <FFXIVRole, int>
            {
                { FFXIVRole.DPS, 0 },
                { FFXIVRole.Healer, 0 },
                { FFXIVRole.Tank, 0 },
            };

            for (ulong i = 0; i < 1000; i++)
            {
                var nextRole = rand.Next(0, 3) switch
                {
                    0 => FFXIVRole.DPS,
                    1 => FFXIVRole.Healer,
                    2 => FFXIVRole.Tank,
                    _ => throw new NotImplementedException(),
                };
                counts[nextRole]++;
                queue.AddSlot(new QueueSlot(i, EventId)
                {
                    QueueTime = DateTime.UtcNow.AddHours(-5),
                }, nextRole);
            }

            var roles    = new[] { FFXIVRole.DPS, FFXIVRole.Healer, FFXIVRole.Tank };
            var timeouts = new Dictionary <FFXIVRole, IEnumerable <ulong> >();

            foreach (var role in roles)
            {
                timeouts[role] = queue.TryQueryTimeout(role, 4 * Time.Hour);
            }
            Assert.That(timeouts[FFXIVRole.DPS].Concat(timeouts[FFXIVRole.Healer]).Concat(timeouts[FFXIVRole.Tank]).Count() == 1000);
            Assert.That(!queue.GetAllSlots().Any());
        }