Description: Use a fake system clock for unit tests.
 .
 This removes a non-deterministic dependency on the real system clock.
Bug-Debian: https://bugs.debian.org/854539
Author: Ben Finney <bignose@debian.org>
Last-Update: 2017-02-18


diff --git i/irc/tests/test_client.py w/irc/tests/test_client.py
index 1e2a8ddb..fd6fb9bf 100644
--- i/irc/tests/test_client.py
+++ w/irc/tests/test_client.py
@@ -44,6 +44,44 @@ class TestHandlers(object):
 		assert not handler1 < handler2
 		assert not handler2 < handler1
 
+
+class FakeClock(object):
+	""" A fake clock that is under control of test cases. """
+
+	_default_initial_seconds = 1450000000.0
+	_default_tick_duration = 0.0005
+
+	def __init__(
+			self,
+			seconds=_default_initial_seconds,
+			tick_duration=_default_tick_duration,
+	):
+		self._tick_duration = tick_duration
+		self.reset(seconds)
+
+	def reset(self, seconds):
+		""" Reset the clock time to `seconds`. """
+		self._seconds = seconds
+
+	def advance(self, seconds):
+		""" Advance the clock by `seconds`. """
+		self._seconds += max(0, seconds)
+
+	def tick(self):
+		""" Advance the clock by its tick duration. """
+		self.advance(self._tick_duration)
+
+	def time(self):
+		""" Get the current time, as seconds since epoch. """
+		self.tick()
+		return self._seconds
+
+
+fake_clock = FakeClock()
+
+
+@mock.patch.object(time, 'time', new=fake_clock.time)
+@mock.patch.object(time, 'sleep', new=fake_clock.advance)
 class TestThrottler(object):
 	def test_function_throttled(self):
 		"""
