summaryrefslogtreecommitdiff
path: root/tests/test_threadpool.c
AgeCommit message (Collapse)Author
2016-02-18Fix failing threadpool_auto_increment test.Mark Michelson
The threadpool_auto_increment test fails infrequently for a couple of reasons * The threadpool listener was notified of fewer tasks being pushed than were actually pushed * The "was_empty" flag was set to an unexpected value. The problem is that the test pushes three tasks into the threadpool. Test expects the threadpool to essentially gather those three tasks, and then distribute those to the threadpool threads. It also expects that as the tasks are pushed in, the threadpool listener is alerted immediately that the tasks have been pushed. In reality, a task can be distributed to the threadpool threads quicker than expected, meaning that the threadpool has already emptied by the time each subsequent task is pushed. In addition, the internal threadpool queue can be delayed so that the threadpool listener is not alerted that a task has been pushed even after the task has been executed. From the test's point of view, there's no way to be able to predict exactly the order that task execution/listener notifications will occur, and there is no way to know which listener notifications will indicate that the threadpool was previously empty. For this reason, the test has been updated to only check the things it can check. It ensures that all tasks get executed, that the threads go idle after the tasks are executed, and that the listener is told the proper number of tasks that were pushed. Change-Id: I7673120d74adad64ae6894594a606e102d9a1f2c
2016-01-19test_threadpool: Wait for each task to complete and fix memory leak.Joshua Colp
This change makes the thread_timeout_thrash unit test wait for each task to complete. This fixes the problem where the test would prematurely end when all threads were gone and a new one had to be started to handle the last task. It also increases the thrasing as it is now more likely for each task to encounter the above scenario. This also fixes a memory leak where the data for each task was not being freed. ASTERISK-25611 #close Change-Id: I5017d621a4dc911f509074c16229b86bff2fb3c6
2015-11-11threadpool: Handle worker thread transitioning to dead when going active.Joshua Colp
This change adds handling of dead worker threads when moving them to be active. When this happens the worker thread is removed from both the active and idle threads container. If no threads are able to be moved to active then the pool grows as configured. A unit test has also been added which thrashes the idle timeout and thread activation to exploit any race conditions between the two. ASTERISK-25546 #close Change-Id: I6c455f9a40de60d9e86458d447b548fb52ba1143
2015-06-24Unit tests: Fix unit test description strings.Richard Mudgett
Analyzing the code shows that the unit test summary and description strings should not end with a new-line character. Where these strings are used in the code a new-line is provided for output. Change-Id: I129284f5e7ca93d82532334076da4c462d3d9fba
2013-02-12Add a serializer interface to the threadpoolDavid M. Lee
This patch adds the ability to create a serializer from a thread pool. A serializer is a ast_taskprocessor with the same contract as a default taskprocessor (tasks execute serially) except instead of executing out of a dedicated thread, execution occurs in a thread from a ast_threadpool. Think of it as a lightweight thread. While it guarantees that each task will complete before executing the next, there is no guarantee as to which thread from the pool individual tasks will execute. This normally only matters if your code relys on thread specific information, such as thread locals. This patch also fixes a bug in how the 'was_empty' parameter is computed for the push callback, and gets rid of the unused 'shutting_down' field. Review: https://reviewboard.asterisk.org/r/2323/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@381326 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-01-17Address David's latest feedback on reviewboard:Mark Michelson
* Add a max_size option for threadpools. Also added a test for this option. * Fixed comments to be more accurate and have fewer typos. * Updated copyright dates on new files. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379375 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-01-15Make the threadpool listener opaque.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379126 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-01-15Make the initial size of the threadpool part of the options passed in.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379123 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-01-15Remove threadpool listener alloc and destroy callbacks.Mark Michelson
This replaces the destroy callback with a shutdown callback instead. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379122 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-01-07Address review board feedback from Matt and RichardMark Michelson
* Remove extraneous whitespace * Bump up debug levels of messages and add identifying info to messages. * Account for potential failures of ao2_link() * Add additional test and some more test data * Add some comments in places where they could be useful * Make threadpool listeners and their callbacks optional git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@378652 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-11Add auto-increment option and accompanying test.Mark Michelson
This allows for the threadpool to automatically grow if tasks are pushed to it and no idle threads are currently available. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377803 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-10Solve the issue about the "CHANGE THIS" and "XXX CHANGE THIS XXX" ↵Mark Michelson
taskprocessor names. Unfortunately, this required a taskprocessor listener change that makes listener allocation utterly silly. I'm going to change the scheme so that allocation of taskprocessor listeners is done internally within taskprocessor code. This will make it parallel with threadpool code, which is a good thing. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377687 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-10Make thread state waiting a little less ugly and not possible to lock up.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377686 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-10Improve timedwaits in tests to actually behave like they should.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377654 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-10Add threadpool options and accompanying test.Mark Michelson
The only test added so far is an idle thread timeout option. This will greatly aid threadpool users who wish to maintain a threadpool by allowing for idle threads to die out as necessary. Test passes. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377580 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-10Improve shutdown procedure.Mark Michelson
This helps tests to pass more often than before. They are far less likely to queue extra processes into the control taskprocessor since they are prevented once the threadpool begins to shut down. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377578 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-09Add some useful debugging in threadpool test failure conditions.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377475 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-09Create longer thread destruction test.Mark Michelson
This one involves shrinking the threadpool in such a way that both idle and active threads are affected. This test made me re-realize why the zombie state exists, so I re-added it. We don't want to clog up the control taskprocessor by waiting on active threads to complete what they are doing. Instead, we mark them as zombies so that when they are done, they can clean themselves up properly. Without the zombie state available, the new test actually will deadlock. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377474 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-08Add a task distribution test.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377418 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-07Add threadpool reactivation test.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377400 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-07Add a single-thread multi-task test.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377397 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-07Add test where we create a thread and push a task.Mark Michelson
Passes! git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377380 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-07Add test where we add a task then create a thread for it.Mark Michelson
It passes. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377379 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-07Add threadpool destruction test.Mark Michelson
It worked on the first try. Fun time. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377378 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-07Fix up categories of threadpool tests.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377369 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-07Add new threadpool test and fix some taskprocessor bugs.Mark Michelson
The new thread creation test fails because Asterisk locks up while trying to lock a taskprocessor. While trying to debug that, I found a race condition during taskprocessor creation where a default taskprocessor listener could try to operate on a partially started taskprocessor. This was fixed by adding a new callback to taskprocessor listeners. Then while testing that change, I found some bugs in the taskprocessor tests where I was not properly unlocking when done with a lock. Scoped locks have spoiled me a bit. I still have not figured out why the threadpool thread creation test is locking up. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377368 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-06Add initial simple threadpool test.Mark Michelson
This one simply pushes a task into the threadpool and ensures that the listener gets the callbacks expected. It currently crashes, so I need to figure out what's wrong. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377351 65c4cc65-6c06-0410-ace0-fbb531ad65f3