~hudson-openstack/burrow/trunk

« back to all changes in this revision

Viewing changes to test/backend/test_memory.py

  • Committer: Tarmac
  • Author(s): Eric Day
  • Date: 2011-08-10 07:28:01 UTC
  • mfrom: (16.3.24 backend-unittests)
  • Revision ID: tarmac-20110810072801-32ue4p8boiepxhjg
Pushed wait functionality down into backend, removed frontend tests since this is replaced with HTTP backend test now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
import time
17
17
import unittest
18
18
 
 
19
import eventlet
 
20
eventlet.monkey_patch(socket=True)
 
21
 
19
22
import burrow.backend
20
23
import burrow.backend.memory
21
24
 
884
887
        self.assertEquals(dict(id='0', ttl=0, hide=0, body='0'), message)
885
888
        self.delete_messages()
886
889
 
 
890
    def test_message_create_wait(self):
 
891
        self.success = False
 
892
        thread = eventlet.spawn(self.get_messages)
 
893
        eventlet.spawn_after(0.2,
 
894
            self.backend.create_message, 'a', 'q', 'm', 'test')
 
895
        thread.wait()
 
896
        self.assertTrue(self.success)
 
897
        self.delete_messages()
 
898
 
 
899
    def test_message_update_wait(self):
 
900
        attributes = dict(hide=100)
 
901
        self.backend.create_message('a', 'q', 'm', 'test', attributes)
 
902
        self.success = False
 
903
        thread = eventlet.spawn(self.get_messages)
 
904
        attributes = dict(hide=0)
 
905
        eventlet.spawn_after(0.2,
 
906
            self.backend.update_message, 'a', 'q', 'm', attributes)
 
907
        thread.wait()
 
908
        self.assertTrue(self.success)
 
909
        self.delete_messages()
 
910
 
 
911
    def test_messages_update_wait(self):
 
912
        attributes = dict(hide=100)
 
913
        self.backend.create_message('a', 'q', 'm', 'test', attributes)
 
914
        self.success = False
 
915
        thread = eventlet.spawn(self.get_messages)
 
916
        attributes = dict(hide=0)
 
917
        filters = dict(match_hidden=True)
 
918
        messages = self.backend.update_messages('a', 'q', attributes, filters)
 
919
        eventlet.spawn_after(0.2, list, messages)
 
920
        thread.wait()
 
921
        self.assertTrue(self.success)
 
922
        self.delete_messages()
 
923
 
887
924
    def delete_messages(self):
888
925
        filters = dict(match_hidden=True)
889
926
        messages = list(self.backend.delete_messages('a', 'q', filters))
890
927
        self.assertEquals([], messages)
 
928
 
 
929
    def get_messages(self):
 
930
        message = dict(id='m', ttl=0, hide=0, body='test')
 
931
        filters = dict(wait=2)
 
932
        messages = list(self.backend.get_messages('a', 'q', filters))
 
933
        self.assertEquals([message], messages)
 
934
        self.success = True