Esempio n. 1
0
    def test_teardown(self):
        try:
            lock = threading.Lock()
            http = http_reader.server_plugin(lock, PORT)
        except Exception as e:
            print e
            self.fail("Failed to startup server")

        try:
            conn = httplib.HTTPConnection('localhost:80')
            conn.request("GET", "/")
            r1 = conn.getresponse()
            if r1.status == 404:
                connection = True
            else:
                connection = False
            conn.close()
        except Exception as e:
            print e
            self.fail("Client couldn't to server")
        try:
            http.tear_down()
            conn = httplib.HTTPConnection('localhost:80')
            r2 = conn.getresponse()
            self.fail("Server failed to shutdown")

        except Exception as e:
            #sever shutdown
            self.assertTrue(True)
Esempio n. 2
0
    def test_invalidPort(self):

        try:
            lock = threading.Lock()
            http = http_reader.server_plugin(lock, PORT)
        except Exception as e:
            self.fail("Server Failed to Start")

        try:
            conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            conn.connect(("localhost", 81))
            connection = False
        except Exception as e:
            print e
            connection = True

        try:
            conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            conn.connect(("localhost", 79))
            connection = False
        except Exception as e:
            print e
            connection = True
        finally:
            self.assertTrue(connection)
            conn.close()
    def test_startUp(self):
        try:
            lock = threading.Lock()
            self.http = http_reader.server_plugin(lock, PORT)

        except Exception as e:
            self.fail("Server Failed to Start")

        time.sleep(1)

        try:
            conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            conn.connect(("localhost", 80))
            connection = True

        except Exception as e:
            print e
            connection = False

        finally:
            self.assertTrue(connection)
            conn.close()
            self.http.server.shutdown()
            self.http.server.server_close()
            time.sleep(1)
    def test_run(self):
        try:
            lock = threading.Lock()
            self.http = http_reader.server_plugin(lock, PORT)

        except Exception as e:
            self.fail("Server Failed to Start")

        time.sleep(1)

        try:
            conn = httplib.HTTPConnection(server_addr)
            conn.request("GET", "/")
            r1 = conn.getresponse()

            if r1.status == 404:
                connection = True

            else:
                connection = False

        except Exception as e:
                print e
                connection = False

        finally:
            self.assertTrue(connection)
            conn.close()
            self.http.server.shutdown()
            self.http.server.server_close()
            time.sleep(1)
    def test_multithreads(self):
        try:
            lock = threading.Lock()
            self.http = http_reader.server_plugin(lock, PORT)

        except Exception as e:
            self.fail("Server Failed to Start")

        time.sleep(1)

        try:
            threads = []

            for num in range(0, 4):
                thread = HttpClient()
                thread.start()
                threads.append(thread)

            for thread in threads:
                thread.join()
            self.assertTrue(True)

        except Exception as e:
            print e
            self.fail("Server is not listening on multiple threads")

        finally:
            self.http.server.shutdown()
            self.http.server.server_close()
            time.sleep(1)