~ubuntu-branches/ubuntu/oneiric/ubuntuone-client/oneiric

« back to all changes in this revision

Viewing changes to tests/syncdaemon/test_hashqueue.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2010-06-08 17:31:18 UTC
  • mto: This revision was merged to the branch mainline in revision 31.
  • Revision ID: james.westby@ubuntu.com-20100608173118-o8s897ll11rtne99
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
from contrib.testing import testcase
33
33
from ubuntuone.syncdaemon import hash_queue
34
 
from ubuntuone.storageprotocol.hash import \
 
34
from ubuntuone.storageprotocol.content_hash import \
35
35
            content_hash_factory, crc32
36
36
 
37
37
 
74
74
        self.assertFalse(hasher.isAlive())
75
75
        hasher.join(timeout=5)
76
76
 
 
77
    @defer.inlineCallbacks
 
78
    def test_called_back_log_ok(self):
 
79
        """Tests that the hasher produces correct info."""
 
80
        # create the hasher
 
81
        mark = object()
 
82
        queue = hash_queue.UniqueQueue()
 
83
        d = defer.Deferred()
 
84
        class Helper(object):
 
85
            """Helper class."""
 
86
            def push(self, *args):
 
87
                """Callback."""
 
88
                d.callback(args)
 
89
        receiver = Helper()
 
90
        hasher = hash_queue._Hasher(queue, mark, receiver)
 
91
        hasher.start()
 
92
 
 
93
        # log config
 
94
        handler = testcase.MementoHandler()
 
95
        handler.setLevel(logging.DEBUG)
 
96
        hasher.logger.addHandler(handler)
 
97
 
 
98
        # send what to hash
 
99
        testfile = os.path.join(self.test_dir, "testfile")
 
100
        with open(testfile, "w") as fh:
 
101
            fh.write("foobar")
 
102
        queue.put((testfile, "mdid"))
 
103
 
 
104
        # wait event and stop hasher
 
105
        yield d
 
106
        hasher.stop()
 
107
        hasher.join(timeout=5)
 
108
 
 
109
        # check log
 
110
        log_msg = [r.message for r in handler.records
 
111
                   if "path hash pushed" in r.message][0]
 
112
        self.assertTrue("path" in log_msg)
 
113
        self.assertTrue("hash" in log_msg)
 
114
        self.assertTrue("crc" in log_msg)
 
115
        self.assertTrue("size" in log_msg)
 
116
        self.assertTrue("st_ino" in log_msg)
 
117
        self.assertTrue("st_size" in log_msg)
 
118
        self.assertTrue("st_mtime" in log_msg)
 
119
        hasher.logger.removeHandler(handler)
 
120
 
77
121
    def test_called_back_ok(self):
78
122
        """Tests that the hasher produces correct info."""
79
123
        # create the hasher