test_encode.py: refactor send_and_recover a bit
This commit is contained in:
parent
8907e04ef5
commit
c7160af7ee
|
@ -266,19 +266,23 @@ class Roundtrip(unittest.TestCase):
|
||||||
e.setup_codec() # need to rebuild the codec for that change
|
e.setup_codec() # need to rebuild the codec for that change
|
||||||
|
|
||||||
shareholders = {}
|
shareholders = {}
|
||||||
all_shareholders = []
|
|
||||||
all_peers = []
|
all_peers = []
|
||||||
for shnum in range(NUM_SHARES):
|
for shnum in range(NUM_SHARES):
|
||||||
mode = bucket_modes.get(shnum, "good")
|
mode = bucket_modes.get(shnum, "good")
|
||||||
peer = FakeBucketWriter(mode)
|
peer = FakeBucketWriter(mode)
|
||||||
shareholders[shnum] = peer
|
shareholders[shnum] = peer
|
||||||
all_shareholders.append(peer)
|
|
||||||
e.set_shareholders(shareholders)
|
e.set_shareholders(shareholders)
|
||||||
e.set_thingA_data({'verifierid': "V" * 20,
|
e.set_thingA_data({'verifierid': "V" * 20,
|
||||||
'fileid': "F" * 20,
|
'fileid': "F" * 20,
|
||||||
})
|
})
|
||||||
d = e.start()
|
d = e.start()
|
||||||
def _uploaded(thingA_hash):
|
d.addCallback(self.recover, nonkey, e, shareholders, AVAILABLE_SHARES)
|
||||||
|
def _downloaded(newdata):
|
||||||
|
self.failUnless(newdata == data)
|
||||||
|
d.addCallback(_downloaded)
|
||||||
|
return d
|
||||||
|
|
||||||
|
def recover(self, thingA_hash, nonkey, e, shareholders, AVAILABLE_SHARES):
|
||||||
URI = pack_uri(storage_index="S" * 20,
|
URI = pack_uri(storage_index="S" * 20,
|
||||||
key=nonkey,
|
key=nonkey,
|
||||||
thingA_hash=thingA_hash,
|
thingA_hash=thingA_hash,
|
||||||
|
@ -304,20 +308,13 @@ class Roundtrip(unittest.TestCase):
|
||||||
'total_shares': e.num_shares,
|
'total_shares': e.num_shares,
|
||||||
}
|
}
|
||||||
fd._got_thingA(thingA_data)
|
fd._got_thingA(thingA_data)
|
||||||
for shnum in range(AVAILABLE_SHARES):
|
for shnum, bucket in shareholders.items():
|
||||||
bucket = all_shareholders[shnum]
|
if shnum < AVAILABLE_SHARES and bucket.closed:
|
||||||
if bucket.closed:
|
|
||||||
fd.add_share_bucket(shnum, bucket)
|
fd.add_share_bucket(shnum, bucket)
|
||||||
fd._got_all_shareholders(None)
|
fd._got_all_shareholders(None)
|
||||||
fd._create_validated_buckets(None)
|
fd._create_validated_buckets(None)
|
||||||
d2 = fd._download_all_segments(None)
|
d = fd._download_all_segments(None)
|
||||||
d2.addCallback(fd._done)
|
d.addCallback(fd._done)
|
||||||
return d2
|
|
||||||
d.addCallback(_uploaded)
|
|
||||||
def _downloaded(newdata):
|
|
||||||
self.failUnless(newdata == data)
|
|
||||||
d.addCallback(_downloaded)
|
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_not_enough_shares(self):
|
def test_not_enough_shares(self):
|
||||||
|
|
Loading…
Reference in New Issue