Ticket #999: storagemocktest01.darcs.patch

File storagemocktest01.darcs.patch, 5.9 KB (added by arch_o_median, at 2011-03-22T05:34:38Z)
Line 
1Mon Mar 21 23:28:10 MDT 2011  wilcoxjg@gmail.com
2  * storage: add test of read share data
3  There are already tests in test_download.py which exercise the whole stack including the client and the real operating system's filesystem access functions; this test mocks out the filesystem access functions and invokes the StorageServer interface.
4
5New patches:
6
7[storage: add test of read share data
8wilcoxjg@gmail.com**20110322052810
9 Ignore-this: 19e9fc3864a65dd4f1eb4460f3be4344
10 There are already tests in test_download.py which exercise the whole stack including the client and the real operating system's filesystem access functions; this test mocks out the filesystem access functions and invokes the StorageServer interface.
11] {
12addfile ./src/allmydata/test/test_server.py
13hunk ./src/allmydata/test/test_server.py 1
14+from twisted.trial import unittest
15+
16+from StringIO import StringIO
17+
18+from allmydata.test.common_util import ReallyEqualMixin
19+
20+import mock
21+
22+# This is the code that we're going to be testing.
23+from allmydata.storage.server import StorageServer
24+
25+class TestServer(unittest.TestCase, ReallyEqualMixin):
26+    @mock.patch('os.path.getsize')
27+    @mock.patch('__builtin__.open')
28+    @mock.patch('os.listdir')
29+    def test_reads_old_share_from_disk(self, mocklistdir, mockopen, mockgetsize):
30+        """ This tests whether the code correctly finds and reads
31+        shares written out by old (Tahoe-LAFS <= v1.8.2)
32+        servers. There is a similar test in test_download, but that one
33+        is from the perspective of the client and exercises a deeper
34+        stack of code. This one is for exercising just the
35+        StorageServer object. """
36+
37+        mocklistdir.return_value = ['0']
38+
39+        # The following share file contents was generated with
40+        # storage.immutable.ShareFile from Tahoe-LAFS v1.8.2
41+        # with share data == 'a'.
42+        share_data = 'a\x00\x00\x00\x00xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\x00\x00\x00\x07'
43+        share_file_data = '\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01' + share_data
44+
45+        sharefname = 'testdir/shares/or/orsxg5dtorxxeylhmvpws3temv4a/0'
46+        def call_open(fname, mode):
47+            if fname == 'testdir/bucket_counter.state':
48+                raise IOError(2, "No such file or directory: 'testdir/bucket_counter.state'")
49+            elif fname == 'testdir/lease_checker.state':
50+                raise IOError(2, "No such file or directory: 'testdir/lease_checker.state'")
51+            elif fname == 'testdir/lease_checker.history':
52+                return StringIO()
53+            else:
54+                self.failUnlessReallyEqual(fname, sharefname)
55+                self.failUnless('r' in mode, mode)
56+                self.failUnless('b' in mode, mode)
57+
58+                return StringIO(share_file_data)
59+        mockopen.side_effect = call_open
60+
61+        datalen = len(share_file_data)
62+        def call_getsize(fname):
63+            self.failUnlessReallyEqual(fname, sharefname)
64+            return datalen
65+        mockgetsize.side_effect = call_getsize
66+
67+       
68+        # Now begin the test.
69+        s = StorageServer('testdir', 'testnodeidxxxxxxxxxx')
70+
71+        bs = s.remote_get_buckets('teststorage_index')
72+
73+        self.failUnlessEqual(len(bs), 1)
74+        b = bs[0]
75+        self.failUnlessReallyEqual(b.remote_read(0, datalen), share_data)
76+        # If you try to read past the end you get the as much data as is there.
77+        self.failUnlessReallyEqual(b.remote_read(0, datalen+20), share_data)
78+        # If you start reading past the end of the file you get the empty string.
79+        self.failUnlessReallyEqual(b.remote_read(datalen+1, 3), '')
80}
81
82Context:
83
84[test: increase timeout on a network test because Francois's ARM machine hit that timeout
85zooko@zooko.com**20110317165909
86 Ignore-this: 380c345cdcbd196268ca5b65664ac85b
87 I'm skeptical that the test was proceeding correctly but ran out of time. It seems more likely that it had gotten hung. But if we raise the timeout to an even more extravagant number then we can be even more certain that the test was never going to finish.
88]
89[docs/configuration.rst: add a "Frontend Configuration" section
90Brian Warner <warner@lothar.com>**20110222014323
91 Ignore-this: 657018aa501fe4f0efef9851628444ca
92 
93 this points to docs/frontends/*.rst, which were previously underlinked
94]
95[web/filenode.py: avoid calling req.finish() on closed HTTP connections. Closes #1366
96"Brian Warner <warner@lothar.com>"**20110221061544
97 Ignore-this: 799d4de19933f2309b3c0c19a63bb888
98]
99[Add unit tests for cross_check_pkg_resources_versus_import, and a regression test for ref #1355. This requires a little refactoring to make it testable.
100david-sarah@jacaranda.org**20110221015817
101 Ignore-this: 51d181698f8c20d3aca58b057e9c475a
102]
103[allmydata/__init__.py: .name was used in place of the correct .__name__ when printing an exception. Also, robustify string formatting by using %r instead of %s in some places. fixes #1355.
104david-sarah@jacaranda.org**20110221020125
105 Ignore-this: b0744ed58f161bf188e037bad077fc48
106]
107[Refactor StorageFarmBroker handling of servers
108Brian Warner <warner@lothar.com>**20110221015804
109 Ignore-this: 842144ed92f5717699b8f580eab32a51
110 
111 Pass around IServer instance instead of (peerid, rref) tuple. Replace
112 "descriptor" with "server". Other replacements:
113 
114  get_all_servers -> get_connected_servers/get_known_servers
115  get_servers_for_index -> get_servers_for_psi (now returns IServers)
116 
117 This change still needs to be pushed further down: lots of code is now
118 getting the IServer and then distributing (peerid, rref) internally.
119 Instead, it ought to distribute the IServer internally and delay
120 extracting a serverid or rref until the last moment.
121 
122 no_network.py was updated to retain parallelism.
123]
124[TAG allmydata-tahoe-1.8.2
125warner@lothar.com**20110131020101]
126Patch bundle hash:
12701bcb40d26aa13847d26001cf0550614e9b22a47