Start server after test files are created.

This commit is contained in:
Yuxin Wang 2018-10-01 15:17:53 -04:00
parent 8b6dc6a875
commit 2450554ffb

View file

@ -18,10 +18,6 @@ def fmd5(fname):
def test_main(): def test_main():
peer_1, peer_2 = Peer('localhost', 0, 'localhost', 8880), Peer('localhost', 0, 'localhost', 8880) peer_1, peer_2 = Peer('localhost', 0, 'localhost', 8880), Peer('localhost', 0, 'localhost', 8880)
tracker = Tracker('localhost', 8880) tracker = Tracker('localhost', 8880)
tracker.start()
peer_1.start()
peer_2.start()
with open('test_small_file', 'wb') as fout: with open('test_small_file', 'wb') as fout:
fout.write(os.urandom(1000)) fout.write(os.urandom(1000))
@ -29,6 +25,11 @@ def test_main():
# write 500MB random data into the file # write 500MB random data into the file
for _ in range(500): for _ in range(500):
fout.write(os.urandom(1000 * 1000)) fout.write(os.urandom(1000 * 1000))
tracker.start()
peer_1.start()
peer_2.start()
# peer1 publish small file and peer2 downloads it # peer1 publish small file and peer2 downloads it
peer_1.publish('test_small_file') peer_1.publish('test_small_file')
file_list = tracker.file_list() file_list = tracker.file_list()