Exemplo n.º 1
0
def start_server():
    logger.debug('Starting test server on %s:%s' % (ADDRESS, TEST_SERVER_PORT))
    server = TestServer(address=ADDRESS,
                        port=TEST_SERVER_PORT,
                        extra_ports=[EXTRA_PORT1, EXTRA_PORT2])
    server.start()
    '''
    # Ensure that test server works
    old_timeout = socket.getdefaulttimeout()
    ok = False
    for x in range(6):
        socket.setdefaulttimeout(0.5)
        try:
            urlopen('http://localhost:%d/' % TEST_SERVER_PORT).read()
        except Exception as ex:
            logger.error('', exc_info=ex)
            time.sleep(0.1)
        else:
            ok = True
            break
    socket.setdefaulttimeout(old_timeout)
    if not ok:
        raise Exception('Test server does not respond.')
    else:
    '''
    #GLOBAL['test_server'] = server
    return server
Exemplo n.º 2
0
def start_server():
    logger.debug('Starting test server on %s:%s' % (ADDRESS, TEST_SERVER_PORT))
    server = TestServer(address=ADDRESS, port=TEST_SERVER_PORT,
                        extra_ports=[EXTRA_PORT1, EXTRA_PORT2])
    server.start()
    '''
    # Ensure that test server works
    old_timeout = socket.getdefaulttimeout()
    ok = False
    for x in range(6):
        socket.setdefaulttimeout(0.5)
        try:
            urlopen('http://localhost:%d/' % TEST_SERVER_PORT).read()
        except Exception as ex:
            logger.error('', exc_info=ex)
            time.sleep(0.1)
        else:
            ok = True
            break
    socket.setdefaulttimeout(old_timeout)
    if not ok:
        raise Exception('Test server does not respond.')
    else:
    '''
    #GLOBAL['test_server'] = server
    return server
Exemplo n.º 3
0
def start_server():
    logger.debug('Starting test server on %s:%s', ADDRESS, TEST_SERVER_PORT)
    server = TestServer(address=ADDRESS,
                        port=TEST_SERVER_PORT,
                        extra_ports=[EXTRA_PORT1, EXTRA_PORT2])
    server.start()
    return server
Exemplo n.º 4
0
 def setUpClass(cls):
     super(TestProxy, cls).setUpClass()
     cls.extra_servers = {}
     for _ in range(3):
         serv = TestServer(address=ADDRESS)
         serv.start()
         cls.extra_servers[serv.port] = {
             'server': serv,
             'proxy': '%s:%d' % (ADDRESS, serv.port),
         }
Exemplo n.º 5
0
 def setUpClass(cls):
     super(TestSpiderProxyCase, cls).setUpClass()
     cls.extra_servers = {}
     for cnt in range(3):
         serv = TestServer(address=ADDRESS, port=TEST_SERVER_PORT + 1 + cnt)
         serv.start()
         cls.extra_servers[serv.port] = {
             'server': serv,
             'proxy': '%s:%d' % (ADDRESS, serv.port),
         }
Exemplo n.º 6
0
 def setUpClass(cls):
     super(TestSpiderProxyCase, cls).setUpClass()
     cls.extra_servers = {}
     for cnt in range(3):
         serv = TestServer(address=ADDRESS, port=TEST_SERVER_PORT + 1 + cnt)
         serv.start()
         cls.extra_servers[serv.port] = {
             'server': serv,
             'proxy': '%s:%d' % (ADDRESS, serv.port),
         }
Exemplo n.º 7
0
    def test_post(self):
        server = TestServer(5001)
        server.set_response_data(json.dumps({'c': 3, 'd': 4}))
        server.start()

        stackimpact._agent = None
        agent = stackimpact.start(dashboard_address='http://localhost:5001',
                                  agent_key='key1',
                                  app_name='TestPythonApp',
                                  app_environment='test',
                                  app_version='1.1.1',
                                  debug=True)

        api_request = APIRequest(agent)

        api_request.post('test', {'a': 1, 'b': 2})
        data = json.loads(server.get_request_data())
        self.assertEqual(data['run_id'], agent.run_id)
        self.assertEqual(data['run_ts'], agent.run_ts)
        self.assertEqual(data['process_id'], os.getpid())
        self.assertEqual(data['host_name'], socket.gethostname())
        self.assertEqual(data['runtime_type'], 'python')
        self.assertEqual(
            data['runtime_version'],
            '{0.major}.{0.minor}.{0.micro}'.format(sys.version_info))
        self.assertEqual(data['agent_version'], agent.AGENT_VERSION)
        self.assertEqual(data['app_name'], 'TestPythonApp')
        self.assertEqual(data['app_environment'], 'test')
        self.assertEqual(data['app_version'], '1.1.1')
        self.assertEqual(data['payload'], {'a': 1, 'b': 2})

        agent.destroy()
        server.join()
Exemplo n.º 8
0
def global_server():
    if not STATE['server']:
        print('[!] Starting server')
        srv = TestServer(port=9999)
        srv.start(daemon=True)
        STATE['server'] = srv
    yield STATE['server']
    if STATE['server']:
        print('[!] Stoping server')
        STATE['server'].stop()
        STATE['server'] = None
    def test_flush_fail(self):
        server = TestServer(5005)
        server.set_response_data("unparsablejson")
        server.start()

        stackimpact._agent = None
        agent = stackimpact.start(
            dashboard_address = 'http://localhost:5005',
            agent_key = 'key1',
            app_name = 'TestPythonApp',
            debug = True
        )

        m = {
            'm1': 1
        }
        agent.message_queue.add('t1', m)

        m = {
            'm2': 2
        }        
        agent.message_queue.add('t1', m)

        agent.message_queue.flush()
        self.assertEqual(len(agent.message_queue.queue), 2)

        agent.destroy()
        server.join()
    def test_flush_fail(self):
        server = TestServer(5006)
        server.set_response_data("unparsablejson")
        server.start()

        stackimpact._agent = None
        agent = stackimpact.start(
            dashboard_address = 'http://localhost:5006',
            agent_key = 'key1',
            app_name = 'TestPythonApp',
            debug = True
        )

        m = {
            'm1': 1
        }
        agent.message_queue.add('t1', m)

        m = {
            'm2': 2
        }        
        agent.message_queue.add('t1', m)

        agent.message_queue.flush()
        self.assertEqual(len(agent.message_queue.queue), 2)

        agent.destroy()
        server.join()
Exemplo n.º 11
0
    def test_flush(self):
        server = TestServer(5004)
        server.start()

        stackimpact._agent = None
        agent = stackimpact.start(
            dashboard_address = 'http://localhost:5004',
            agent_key = 'key1',
            app_name = 'TestPythonApp',
            debug = True
        )

        m = {
            'm1': 1
        }
        agent.message_queue.add('t1', m)

        m = {
            'm2': 2
        }        
        agent.message_queue.add('t1', m)

        agent.message_queue.flush()

        data = json.loads(server.get_request_data())
        self.assertEqual(data['payload']['messages'][0]['content']['m1'], 1)
        self.assertEqual(data['payload']['messages'][1]['content']['m2'], 2)

        agent.destroy()
        server.join()
Exemplo n.º 12
0
    def setUpClass(cls):
        # import TestServer locally to avoid
        # pytest warning about skipped TestServer class
        from test_server import TestServer

        cls.test_server = TestServer(address=TEST_SERVER_HOST,
                                     port=TEST_SERVER_PORT,
                                     engine='subprocess')
        cls.test_server.start()
Exemplo n.º 13
0
 def server_process(wait_event, server_queue):
     test_server = TestServer(address=config.TEST_SERVER_HOST_IP,
                              port=config.TEST_SERVER_EXTRA_PORT)
     test_server.start()
     test_server.response['data'] = b'zzz'
     wait_event.wait()
     server_queue.put(test_server.request)
     test_server.stop()
Exemplo n.º 14
0
def test_multiple_start_stop_cycles():
    start_port = 10100
    for cnt in range(30):
        server2 = TestServer(port=start_port + cnt)
        server2.start()
        try:
            server2.response['data'] = b'zorro'
            for _ in range(10):
                data = urlopen(server2.get_url()).read()
                assert data == b'zorro'
        finally:
            server2.stop()
Exemplo n.º 15
0
 def test_multiple_start_stop_cycles(self):
     for x in range(30):
         server = TestServer()
         server.start()
         server.response["data"] = b"zorro"
         for y in range(10):
             data = urlopen(server.get_url()).read()
             self.assertEqual(data, server.response["data"])
         server.stop()
    def test_flush(self):
        server = TestServer(5005)
        server.start()

        stackimpact._agent = None
        agent = stackimpact.start(
            dashboard_address = 'http://localhost:5005',
            agent_key = 'key1',
            app_name = 'TestPythonApp',
            debug = True
        )

        m = {
            'm1': 1
        }
        agent.message_queue.add('t1', m)

        m = {
            'm2': 2
        }        
        agent.message_queue.add('t1', m)

        agent.message_queue.queue[0]['added_at'] = timestamp() - 20 * 60

        agent.message_queue.flush()

        data = json.loads(server.get_request_data())
        self.assertEqual(data['payload']['messages'][0]['content']['m2'], 2)

        agent.destroy()
        server.join()
Exemplo n.º 17
0
def test_request_done_after_start(server):
    server = TestServer(port=10000)
    server.start()
    try:
        assert server.request['done'] is False
    finally:
        server.stop()
Exemplo n.º 18
0
    def test_load(self):
        server = TestServer(5008)
        server.set_response_data('{"profiling_disabled":"yes"}')
        server.start()

        stackimpact._agent = None
        agent = stackimpact.start(dashboard_address='http://localhost:5008',
                                  agent_key='key1',
                                  app_name='TestPythonApp',
                                  debug=True)

        agent.config_loader.load()

        self.assertTrue(agent.config.is_profiling_disabled())

        agent.destroy()
        server.join()
Exemplo n.º 19
0
    def __init__(self, config, event_queue, debug, test):
        super(RouteServer, self).__init__(config, event_queue, debug)
        self.logger.info("Initialize the Route Server")

        self.config = config
        self.event_queue = event_queue

        # create RIB
        self.rib = RIB(self.config)

        if test:
            self.server = TestServer(self.config.base_path, self.config.id)
        else:
            self.server = Server(self.config.route_server.port,
                                 self.config.route_server.key)
        self.run = False
    def test_load(self):
        server = TestServer(5008)
        server.set_response_data('{"profiling_disabled":"yes"}')
        server.start()

        stackimpact._agent = None
        agent = stackimpact.start(
            dashboard_address = 'http://localhost:5008',
            agent_key = 'key1',
            app_name = 'TestPythonApp',
            debug = True
        )

        agent.config_loader.load()
        
        self.assertTrue(agent.config.is_profiling_disabled())

        agent.destroy()
        server.join()
Exemplo n.º 21
0
 def setUpClass(cls):
     cls.test_server = TestServer(address=config.TEST_SERVER_HOST,
                                  port=config.TEST_SERVER_PORT)
     cls.test_server.start()
Exemplo n.º 22
0
 def setUpClass(cls):
     cls.server = TestServer(port=TEST_SERVER_PORT,
                             address=ADDRESS,
                             extra_ports=[EXTRA_PORT1, EXTRA_PORT2])
     cls.server.start()
Exemplo n.º 23
0
 def setUpClass(cls):
     cls.server = TestServer(address=TEST_SERVER_HOST,
                             port=TEST_SERVER_PORT)
     cls.server.start()
Exemplo n.º 24
0
 def url_wait():
     server = TestServer(5010, 0.4, handler)
     server.start()
     urlopen('http://localhost:5010')
     server.join()
Exemplo n.º 25
0
 def setUpClass(cls):
     cls.server = TestServer()
     cls.server.start()
 def url_wait():
     server = TestServer(5010, 0.4, handler)
     server.start()
     urlopen('http://localhost:5010')
     server.join()
Exemplo n.º 27
0
def test_specific_port():
    server = TestServer(address='localhost', port=9876)
    server.start()
    server.response['data'] = b'abc'
    data = urlopen(server.get_url()).read()
    assert data == b'abc'
Exemplo n.º 28
0
#!/usr/bin/python3
from testing import run_test
from testing import Server
from test_cluster import TestCluster
from test_group import TestGroup
from test_list import TestList
from test_insert import TestInsert
from test_pool import TestPool
from test_select import TestSelect
from test_series import TestSeries
from test_server import TestServer
from test_user import TestUser
from test_compression import TestCompression

Server.BUILDTYPE = 'Release'

if __name__ == '__main__':
    # run_test(TestCluster())
    run_test(TestCompression())
    run_test(TestGroup())
    run_test(TestList())
    run_test(TestInsert())
    run_test(TestPool())
    run_test(TestSelect())
    run_test(TestSeries())
    run_test(TestServer())
    run_test(TestUser())
Exemplo n.º 29
0
 def setUpClass(cls):
     cls.server = TestServer(port=TEST_SERVER_PORT)
     cls.server.start()
Exemplo n.º 30
0
 def setUpClass(cls):
     cls.server = TestServer(port=9876)
     cls.server.start()
Exemplo n.º 31
0
Arquivo: util.py Projeto: lorien/grab
def start_server():
    logger.debug('Starting test server on %s:%s', ADDRESS, TEST_SERVER_PORT)
    server = TestServer(address=ADDRESS, port=TEST_SERVER_PORT)
    server.start()
    return server