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()
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()
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()