# Path: coilmq/util/concurrency.py
# class CoilThreadingTimer(CoilTimerBase):
# 
#     def __init__(self, *args, **kwargs):
#         super(CoilThreadingTimer, self).__init__(*args, **kwargs)
#         self._running = False
# 
#     def run(self):
#         def run_job(interval, callback):
#             if self._running:
#                 threading.Timer(interval, run_job, args=(interval, callback)).start()
#                 callback()
#         for period, job in self.jobs:
#             run_job(period, job)
# 
#     def start(self):
#         self._running = True
#         self.run()
# 
#     def stop(self):
#         self._running = False


import unittest
import time
import threading
from coilmq.util.concurrency import CoilThreadingTimer



class CoilTimerTestCase(unittest.TestCase):

    def setUp(self):
        class CountedCallback(object):

            def __init__(self):
                self.lock = threading.Lock()
                self.n_called = 0

            def __call__(self, *args, **kwargs):
                with self.lock:
                    self.n_called += 1

        self.counter = CountedCallback

    def test_periodic_callback(self):
        period = 0.1
        factor = 10
        counter = self.counter()

# Path: coilmq/util/concurrency.py
# class CoilThreadingTimer(CoilTimerBase):
# 
#     def __init__(self, *args, **kwargs):
#         super(CoilThreadingTimer, self).__init__(*args, **kwargs)
#         self._running = False
# 
#     def run(self):
#         def run_job(interval, callback):
#             if self._running:
#                 threading.Timer(interval, run_job, args=(interval, callback)).start()
#                 callback()
#         for period, job in self.jobs:
#             run_job(period, job)
# 
#     def start(self):
#         self._running = True
#         self.run()
# 
#     def stop(self):
#         self._running = False


# Path: tests/test_util.py
import unittest
import time
import threading
from coilmq.util.concurrency import CoilThreadingTimer




class CoilTimerTestCase(unittest.TestCase):

    def setUp(self):
        class CountedCallback(object):

            def __init__(self):
                self.lock = threading.Lock()
                self.n_called = 0

            def __call__(self, *args, **kwargs):
                with self.lock:
                    self.n_called += 1

        self.counter = CountedCallback

    def test_periodic_callback(self):
        period = 0.1
        factor = 10
        counter = self.counter()

        timer = CoilThreadingTimer()