Exemplo n.º 1
0
class GeneralNetworkConnection(unittest.TestCase):
	def setUp(self):
		self.s = TCP_server(HOST,
							EVENT_SOURCE_PORT,
							USER_CLIENT_PORT,
							BUFFER_SIZE,
							timeout=TIMEOUT,
							test_mode=False)
	
	def tearDown(self):
		self.s.stop_server()
		sleep(2) # Allow time for sockets to be releases and threads to terminate
		self.s = None
	
	def test_5_continuous_running(self):
		# Run follower maze twice with no errors. Reset message counter in between
		SEED=666
		EVENTS=1000
		CONCURRENCY=7
		self.s.start_server()
		command = "time java -server -XX:-UseConcMarkSweepGC -Xmx2G -jar ./follower-maze2/FollowerMaze-assembly-1.0.jar {0} {1} {2} > maze.log".format(SEED,EVENTS,CONCURRENCY)
		for i in xrange(2):
			ret = os.system(command)
			self.assertEqual(ret, 0)
			self.s.EP.next_msg = 1
	
	def test_6a_get_connection(self):
		# Test bad port number
		c = self.s.get_connection(HOST, -1)
		self.assertEqual(c, None)

	def test_6b_get_connection(self):
		# Test bad host name
		c = self.s.get_connection('None', USER_CLIENT_PORT)
		self.assertEqual(c, None)
Exemplo n.º 2
0
class GeneralTesting(unittest.TestCase):
	def setUp(self):
		self.s = TCP_server(HOST,
							EVENT_SOURCE_PORT,
							USER_CLIENT_PORT,
							BUFFER_SIZE,
							timeout=TIMEOUT,
							test_mode=True)
	
	def tearDown(self):
		self.s.stop_server()
		sleep(10) # Allow time for sockets to be released and threads to terminate
		self.s = None
	
	def test_1_followermaze(self):
		# Run follower maze, catch output and get
		SEED=666
		EVENTS=1000
		CONCURRENCY=7
		self.s.start_server()
		command = "time java -server -XX:-UseConcMarkSweepGC -Xmx2G -jar ./follower-maze2/FollowerMaze-assembly-1.0.jar {0} {1} {2} > maze.log".format(SEED,EVENTS,CONCURRENCY)
		ret = os.system(command)
		# while not self.s.stop.is_set():
		# 	pass
		self.assertEqual(ret, 0)
	
	def test_2_timeout(self):
		# Check timeout is accurate to +/- 2s. This will allow time for the threads to close
		start = time()
		self.s.start_server()
		while not self.s.stop.is_set():
			elapsed = time()-start
			if elapsed > TIMEOUT*2: break # Just in case the timeout fails
		self.assertAlmostEqual(elapsed, TIMEOUT, delta=2)
Exemplo n.º 3
0
class ServerFunctions(unittest.TestCase):
	def setUp(self):
		self.s = TCP_server(HOST,
							EVENT_SOURCE_PORT,
							USER_CLIENT_PORT,
							BUFFER_SIZE,
							timeout=TIMEOUT,
							test_mode=True)
	
	def tearDown(self):
		self.s.stop_server()
		sleep(2)
		self.s = None

	def test_8_numerical_arguments(self):
		self.assertRaises(ValueError, TCP_server, HOST, EVENT_SOURCE_PORT, USER_CLIENT_PORT, BUFFER_SIZE, timeout=-1)
		self.assertRaises(ValueError, TCP_server, HOST, EVENT_SOURCE_PORT, USER_CLIENT_PORT, BUFFER_SIZE, maxqueue=0)
		self.assertRaises(ValueError, TCP_server, HOST, EVENT_SOURCE_PORT, USER_CLIENT_PORT, 0)

	def test_9_thread_start_point(self):
		# Starting server should introduce 4 new threads
		num_after_init = threading.active_count()
		self.s.start_server()
		sleep(5)
		self.assertEqual(threading.active_count()-num_after_init, 4)

	def test_10_stop_server(self):
		# Check no exceptions are raised regardless of connection state
		try:
			self.s.start_server()
			self.s.stop_server()
			self.s.stop_server()
			sleep(2) # wait for exceptions
			result = True
		except:
			result = False
		self.assertTrue(result)
	
	def test_11_add_client(self):
		self.s.add_client(0, None, None)
		self.assertEqual(len(self.s.clients), 1)
		self.s.add_client(0, None, None)
		self.assertEqual(len(self.s.clients), 1)
		
	def test_12_reset_timer(self):
		self.s.TO.start()
		sleep(1)
		self.s.reset_timer()
		after_reset = time()
		self.assertAlmostEqual(self.s.TO.get_last_reset(), after_reset, places=3)
Exemplo n.º 4
0
class GeneralNetworkConnection(unittest.TestCase):
    def setUp(self):
        self.s = TCP_server(HOST,
                            EVENT_SOURCE_PORT,
                            USER_CLIENT_PORT,
                            BUFFER_SIZE,
                            timeout=TIMEOUT,
                            test_mode=False)

    def tearDown(self):
        self.s.stop_server()
        sleep(
            2
        )  # Allow time for sockets to be releases and threads to terminate
        self.s = None

    def test_5_continuous_running(self):
        # Run follower maze twice with no errors. Reset message counter in between
        SEED = 666
        EVENTS = 1000
        CONCURRENCY = 7
        self.s.start_server()
        command = "time java -server -XX:-UseConcMarkSweepGC -Xmx2G -jar ./follower-maze2/FollowerMaze-assembly-1.0.jar {0} {1} {2} > maze.log".format(
            SEED, EVENTS, CONCURRENCY)
        for i in xrange(2):
            ret = os.system(command)
            self.assertEqual(ret, 0)
            self.s.EP.next_msg = 1

    def test_6a_get_connection(self):
        # Test bad port number
        c = self.s.get_connection(HOST, -1)
        self.assertEqual(c, None)

    def test_6b_get_connection(self):
        # Test bad host name
        c = self.s.get_connection('None', USER_CLIENT_PORT)
        self.assertEqual(c, None)
Exemplo n.º 5
0
class GeneralTesting(unittest.TestCase):
    def setUp(self):
        self.s = TCP_server(HOST,
                            EVENT_SOURCE_PORT,
                            USER_CLIENT_PORT,
                            BUFFER_SIZE,
                            timeout=TIMEOUT,
                            test_mode=True)

    def tearDown(self):
        self.s.stop_server()
        sleep(
            10
        )  # Allow time for sockets to be released and threads to terminate
        self.s = None

    def test_1_followermaze(self):
        # Run follower maze, catch output and get
        SEED = 666
        EVENTS = 1000
        CONCURRENCY = 7
        self.s.start_server()
        command = "time java -server -XX:-UseConcMarkSweepGC -Xmx2G -jar ./follower-maze2/FollowerMaze-assembly-1.0.jar {0} {1} {2} > maze.log".format(
            SEED, EVENTS, CONCURRENCY)
        ret = os.system(command)
        # while not self.s.stop.is_set():
        # 	pass
        self.assertEqual(ret, 0)

    def test_2_timeout(self):
        # Check timeout is accurate to +/- 2s. This will allow time for the threads to close
        start = time()
        self.s.start_server()
        while not self.s.stop.is_set():
            elapsed = time() - start
            if elapsed > TIMEOUT * 2: break  # Just in case the timeout fails
        self.assertAlmostEqual(elapsed, TIMEOUT, delta=2)
Exemplo n.º 6
0
class ServerFunctions(unittest.TestCase):
    def setUp(self):
        self.s = TCP_server(HOST,
                            EVENT_SOURCE_PORT,
                            USER_CLIENT_PORT,
                            BUFFER_SIZE,
                            timeout=TIMEOUT,
                            test_mode=True)

    def tearDown(self):
        self.s.stop_server()
        sleep(2)
        self.s = None

    def test_8_numerical_arguments(self):
        self.assertRaises(ValueError,
                          TCP_server,
                          HOST,
                          EVENT_SOURCE_PORT,
                          USER_CLIENT_PORT,
                          BUFFER_SIZE,
                          timeout=-1)
        self.assertRaises(ValueError,
                          TCP_server,
                          HOST,
                          EVENT_SOURCE_PORT,
                          USER_CLIENT_PORT,
                          BUFFER_SIZE,
                          maxqueue=0)
        self.assertRaises(ValueError, TCP_server, HOST, EVENT_SOURCE_PORT,
                          USER_CLIENT_PORT, 0)

    def test_9_thread_start_point(self):
        # Starting server should introduce 4 new threads
        num_after_init = threading.active_count()
        self.s.start_server()
        sleep(5)
        self.assertEqual(threading.active_count() - num_after_init, 4)

    def test_10_stop_server(self):
        # Check no exceptions are raised regardless of connection state
        try:
            self.s.start_server()
            self.s.stop_server()
            self.s.stop_server()
            sleep(2)  # wait for exceptions
            result = True
        except:
            result = False
        self.assertTrue(result)

    def test_11_add_client(self):
        self.s.add_client(0, None, None)
        self.assertEqual(len(self.s.clients), 1)
        self.s.add_client(0, None, None)
        self.assertEqual(len(self.s.clients), 1)

    def test_12_reset_timer(self):
        self.s.TO.start()
        sleep(1)
        self.s.reset_timer()
        after_reset = time()
        self.assertAlmostEqual(self.s.TO.get_last_reset(),
                               after_reset,
                               places=3)