Skip to content

Commit

Permalink
[+] add test for LongRunning case in GetWorker(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZjzMisaka committed Sep 27, 2024
1 parent 0401bf1 commit d363791
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions UnitTest/PowerPoolTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,76 @@ public void TestLongWork()
Assert.Equal(0, powerPool.LongRunningWorkerCount);
}

[Fact]
public void TestLongWorkWithNormalWork()
{
PowerPool powerPool = new PowerPool();
powerPool.PowerPoolOption = new PowerPoolOption()
{
MaxThreads = 1,
DestroyThreadOption = new DestroyThreadOption() { MinThreads = 1, KeepAliveTime = 10000 }
};

powerPool.QueueWorkItem(() =>
{
while (true)
{
Thread.Sleep(10);
if (powerPool.CheckIfRequestedStop())
{
return;
}
}
}, new WorkOption()
{
LongRunning = true,
});

Thread.Sleep(100);

powerPool.QueueWorkItem(() =>
{
Thread.Sleep(100);
}, new WorkOption()
{
});
powerPool.QueueWorkItem(() =>
{
Thread.Sleep(100);
}, new WorkOption()
{
});
powerPool.QueueWorkItem(() =>
{
Thread.Sleep(100);
}, new WorkOption()
{
});
powerPool.QueueWorkItem(() =>
{
Thread.Sleep(100);
}, new WorkOption()
{
});
powerPool.QueueWorkItem(() =>
{
Thread.Sleep(100);
}, new WorkOption()
{
});

Thread.Sleep(10);

powerPool.Stop();

Thread.Sleep(500);

Assert.Equal(0, powerPool.RunningWorkerCount);
Assert.Equal(2, powerPool.AliveWorkerCount);
Assert.Equal(2, powerPool.IdleWorkerCount);
Assert.Equal(0, powerPool.LongRunningWorkerCount);
}

[Fact]
public void TestLongWorkForceStop()
{
Expand Down

0 comments on commit d363791

Please sign in to comment.