'Tests the message is delayed and dispatched when due'

def test_delay_message(self):

    Channel(u'asgi.delay').send({u'channel': u'test', u'delay': 1000, u'content': {u'test': u'value'}}, immediately=True)
    worker = PatchedWorker(channel_layers[DEFAULT_CHANNEL_LAYER])
    worker.termed = 1
    worker.run()
    self.assertEqual(DelayedMessage.objects.count(), 1)
    with mock.patch(u'django.utils.timezone.now', return_value=(timezone.now() + timedelta(milliseconds=1001))):
        worker.termed = 1
        worker.run()
    self.assertEqual(DelayedMessage.objects.count(), 0)
    message = self.get_next_message(u'test', require=True)
    self.assertEqual(message.content, {u'test': u'value'})
