Permalink
Browse files

actually adding the tests this time

  • Loading branch information...
1 parent a854da2 commit 962a00327bd5cefca4bacabc10f73becd2b8189c BuzzTroll committed Sep 2, 2010
@@ -0,0 +1,125 @@
+import string
+import random
+import os
+import sys
+import nose.tools
+import sys
+import time
+import unittest
+import tempfile
+import filecmp
+import uuid
+import traceback
+from pylantorrent.client import *
+from pylantorrent.server import *
+
+
+
+class TestManyXfer(unittest.TestCase):
+
+ def setUp(self):
+ self.src_file = "/etc/group"
+ self.src_size = os.path.getsize(self.src_file)
+ self.ports_a = os.environ['LANTORRENT_TEST_PORTS'].split(",")
+ self.files = []
+
+ def tearDown(self):
+ while len(self.files) > 0:
+ f = self.files.pop(0)
+ ## os.remove(f)
+
+ def _t_new_dest(self, host, port, sz=128*1024):
+ (osf, fname) = tempfile.mkstemp()
+ self.files.append(fname)
+
+ ent = pylantorrent.create_endpoint_entry(host, fname, self.src_size, port=int(port), block_size=sz)
+
+ os.close(osf)
+ return (fname, ent)
+
+ def _t_file_compare(self, f):
+ rc = filecmp.cmp(self.src_file, f)
+ self.assertTrue(rc)
+
+ def _t_build_list(self):
+ new_files = []
+ dests = []
+ for port in self.ports_a:
+ (fname, ent) = self._t_new_dest("localhost", port)
+ dests.append(ent)
+ new_files.append(fname)
+ print "sending to %s" % (fname)
+
+ top = dests.pop(0)
+ top['destinations'] = dests
+ print top
+
+ return (top, new_files)
+
+
+ def send_to_all_test(self):
+ (top, new_files) = self._t_build_list()
+
+ c = LTClient(self.src_file, top)
+ v = LTServer(c, c)
+ v.store_and_forward()
+
+ for f in new_files:
+ self._t_file_compare(f)
+ print f
+
+ def fail_end_test(self):
+ (top, new_files) = self._t_build_list()
+ dest = top['destinations']
+
+ (fname, bad_ent) = self._t_new_dest("notahost", 5150)
+ dest.append(bad_ent)
+ top['destinations'] = dest
+
+ c = LTClient(self.src_file, top)
+ v = LTServer(c, c)
+ v.store_and_forward()
+
+ # even tho there is a bad file in the mix, all the good ones should
+ # work
+ for f in new_files:
+ self._t_file_compare(f)
+ print f
+
+ def fail_top_test(self):
+ (top, new_files) = self._t_build_list()
+ dest = top['destinations']
+
+ (fname, bad_ent) = self._t_new_dest("notahost", 5150)
+ dest.insert(0, bad_ent)
+ top['destinations'] = dest
+
+ c = LTClient(self.src_file, top)
+ v = LTServer(c, c)
+ v.store_and_forward()
+
+ # even tho there is a bad file in the mix, all the good ones should
+ # work
+ for f in new_files:
+ self._t_file_compare(f)
+ print f
+
+ def fail_mid_test(self):
+ (top, new_files) = self._t_build_list()
+ dest = top['destinations']
+
+ (fname, bad_ent) = self._t_new_dest("notahost", 5150)
+ ndx = len(dest) / 2
+ dest.insert(ndx, bad_ent)
+ top['destinations'] = dest
+
+ c = LTClient(self.src_file, top)
+ v = LTServer(c, c)
+ v.store_and_forward()
+
+ # even tho there is a bad file in the mix, all the good ones should
+ # work
+ for f in new_files:
+ self._t_file_compare(f)
+ print f
+
@@ -0,0 +1 @@
+export LANTORRENT_TEST_PORTS=24308,30460,9879,2316
@@ -0,0 +1,64 @@
+import string
+import random
+import os
+import sys
+import nose.tools
+import sys
+import time
+import unittest
+import tempfile
+import filecmp
+import uuid
+import traceback
+from pylantorrent.client import *
+from pylantorrent.server import *
+
+
+
+class TestSimple(unittest.TestCase):
+
+ def setUp(self):
+ self.host = "localhost"
+ self.src_file = "/etc/group"
+ self.src_size = os.path.getsize(self.src_file)
+
+ def tearDown(self):
+ pass
+
+ def test_xfer_one_null_no_check(self):
+ final = pylantorrent.create_endpoint_entry(self.host, "/dev/null", self.src_size)
+ final['destinations'] = []
+ c = LTClient(self.src_file, final)
+ v = LTServer(c, c)
+ v.store_and_forward()
+
+ def _t_xfer_one_file_check(self, sz=128*1024):
+ (osf, fname) = tempfile.mkstemp()
+
+ try:
+ final = pylantorrent.create_endpoint_entry(self.host, fname, self.src_size, block_size=sz)
+ final['destinations'] = []
+ c = LTClient(self.src_file, final)
+ v = LTServer(c, c)
+ v.store_and_forward()
+
+ rc = filecmp.cmp(self.src_file, fname)
+ self.assertTrue(rc)
+ finally:
+ os.close(osf)
+ os.remove(fname)
+
+ def test_xfer_one_file_check(self):
+ self._t_xfer_one_file_check()
+
+
+ # some times odd block sizes can cause fiel corruption
+ def test_block_sizes(self):
+ sizes = [11, 23, 53, 997, 5093]
+ for sz in sizes:
+ self._t_xfer_one_file_check(sz=sz)
+
+
+
+
+
@@ -0,0 +1,60 @@
+import string
+import random
+import os
+import sys
+import nose.tools
+import sys
+import time
+import unittest
+import tempfile
+import filecmp
+import uuid
+import traceback
+from pylantorrent.client import *
+from pylantorrent.server import *
+
+
+
+class TestXfer(unittest.TestCase):
+
+ def setUp(self):
+ self.src_file = "/etc/group"
+ self.host = "localhost"
+ self.src_size = os.path.getsize(self.src_file)
+
+ def tearDown(self):
+ pass
+
+ def test_xfer_one_null_no_check(self):
+ final = pylantorrent.create_endpoint_entry(self.host, "/dev/null", self.src_size)
+ final['destinations'] = []
+ c = LTClient(self.src_file, final)
+ v = LTServer(c, c)
+ v.store_and_forward()
+
+ def _t_xfer_one_file_check(self, sz=128*1024):
+ (osf, fname) = tempfile.mkstemp()
+
+ try:
+ final = pylantorrent.create_endpoint_entry(self.host, fname, self.src_size, block_size=sz)
+ final['destinations'] = []
+ c = LTClient(self.src_file, final)
+ v = LTServer(c, c)
+ v.store_and_forward()
+
+ rc = filecmp.cmp(self.src_file, fname)
+ self.assertTrue(rc)
+ finally:
+ os.close(osf)
+ os.remove(fname)
+
+ def test_xfer_one_file_check(self):
+ self._t_xfer_one_file_check()
+
+
+ # some times odd block sizes can cause fiel corruption
+ def test_block_sizes(self):
+ sizes = [11, 23, 53, 997, 5093]
+ for sz in sizes:
+ self._t_xfer_one_file_check(sz=sz)
+
@@ -0,0 +1,14 @@
+# Simple configuration file for xinetd
+#
+# Some defaults, and include /etc/xinetd.d/
+
+defaults
+{
+
+# Please note that you need a log_type line to be able to use log_on_success
+# and log_on_failure. The default is the following :
+# log_type = SYSLOG daemon info
+
+}
+
+includedir /home/bresnaha/Dev/Nimbus/nimbus/lantorrent/tests/xinetd.d
@@ -0,0 +1,17 @@
+# default: off
+# description: An RFC 868 time server. This protocol provides a
+# site-independent, machine readable date and time. The Time service sends back
+# to the originating source the time in seconds since midnight on January first
+# 1900.
+# This is the tcp version.
+service lantorrent2316
+{
+ type = UNLISTED
+ disable = no
+ socket_type = stream
+ protocol = tcp
+ user = bresnaha
+ wait = no
+ port = 2316
+ server = /home/bresnaha/Dev/Nimbus/nimbus/lantorrent/bin/lt.sh
+}
@@ -0,0 +1,17 @@
+# default: off
+# description: An RFC 868 time server. This protocol provides a
+# site-independent, machine readable date and time. The Time service sends back
+# to the originating source the time in seconds since midnight on January first
+# 1900.
+# This is the tcp version.
+service lantorrent24308
+{
+ type = UNLISTED
+ disable = no
+ socket_type = stream
+ protocol = tcp
+ user = bresnaha
+ wait = no
+ port = 24308
+ server = /home/bresnaha/Dev/Nimbus/nimbus/lantorrent/bin/lt.sh
+}
@@ -0,0 +1,17 @@
+# default: off
+# description: An RFC 868 time server. This protocol provides a
+# site-independent, machine readable date and time. The Time service sends back
+# to the originating source the time in seconds since midnight on January first
+# 1900.
+# This is the tcp version.
+service lantorrent30460
+{
+ type = UNLISTED
+ disable = no
+ socket_type = stream
+ protocol = tcp
+ user = bresnaha
+ wait = no
+ port = 30460
+ server = /home/bresnaha/Dev/Nimbus/nimbus/lantorrent/bin/lt.sh
+}
@@ -0,0 +1,17 @@
+# default: off
+# description: An RFC 868 time server. This protocol provides a
+# site-independent, machine readable date and time. The Time service sends back
+# to the originating source the time in seconds since midnight on January first
+# 1900.
+# This is the tcp version.
+service lantorrent9879
+{
+ type = UNLISTED
+ disable = no
+ socket_type = stream
+ protocol = tcp
+ user = bresnaha
+ wait = no
+ port = 9879
+ server = /home/bresnaha/Dev/Nimbus/nimbus/lantorrent/bin/lt.sh
+}

0 comments on commit 962a003

Please sign in to comment.