def test_influxdb_publisher_record(self, agent): session = create_session('record') params = {'test_mode': True} res = agent.record(session, params) assert res[0] is True
def test_registry_main(self, agent): session = create_session('main') # Fake a heartbeat by directly registering an Agent # op_codes, feed op_codes = {'operation1': 5, 'operation2': 1} heartbeat_example = [ op_codes, { "agent_address": "observatory.test_agent", "agg_params": {}, "feed_name": "heartbeat", "address": "observatory.test_agent.feeds.heartbeat", "record": False, "session_id": str(time.time()) } ] agent._register_heartbeat(heartbeat_example) params = {'test_mode': True} res = yield agent.main(session, params) assert res[0] is True assert 'observatory.test_agent' in session.data assert session.data['observatory.test_agent']['expired'] is False assert session.data['observatory.test_agent']['time_expired'] is None assert session.data['observatory.test_agent']['op_codes'] == op_codes
def test_registry_main_expire_agent(self, agent): session = create_session('main') # Fake a heartbeat by directly registering an Agent # op_codes, feed op_codes = {'operation1': 5, 'operation2': 1} heartbeat_example = [ op_codes, { "agent_address": "observatory.test_agent", "agg_params": {}, "feed_name": "heartbeat", "address": "observatory.test_agent.feeds.heartbeat", "record": False, "session_id": str(time.time()) } ] agent._register_heartbeat(heartbeat_example) # Make the last_updated time far enough in the past to expire agent.registered_agents['observatory.test_agent'].last_updated = \ time.time() - 6.0 params = {'test_mode': True} res = yield agent.main(session, params) assert agent.registered_agents['observatory.test_agent'].expired is True assert res[0] is True assert 'observatory.test_agent' in session.data assert session.data['observatory.test_agent']['expired'] is True assert session.data['observatory.test_agent'][ 'time_expired'] is not None expected_op_codes = {'operation1': 7, 'operation2': 7} assert session.data['observatory.test_agent'][ 'op_codes'] == expected_op_codes
def test_fake_data_stop_acq_while_running(self, agent): session = create_session('acq') # set running job to 'acq' agent.job = 'acq' res = agent._stop_acq(session, params=None) assert res[0] is True
def test_registry_stop_main_while_running(self, agent): session = create_session('main') # Fake run main process agent._run = True res = agent._stop_main(session, params=None) assert res[0] is True
def test_fake_data_acq(agent): session = create_session('acq') params = {'test_mode': True} res = agent.acq(session, params=params) assert res[0] is True assert 'fields' in session.data assert 'timestamp' in session.data channels = ['channel_00', 'channel_01'] assert all([ch in channels for ch in session.data['fields']])
def test_aggregator_agent_record_no_data(self, agent, tmpdir): # repoint data_dir to tmpdir fixture agent.data_dir = tmpdir session = create_session('record') params = {'test_mode': True} res = agent.record(session, params) assert res[0] is True
def test_influxdb_publisher_record_data(self, agent, tmpdir): # repoint data_dir to tmpdir fixture agent.data_dir = tmpdir agent.aggregate = True session = create_session('record') # inject some data to the queue data = generate_data_for_queue() agent._enqueue_incoming_data(data) params = {'test_mode': True} res = agent.record(session, params) assert res[0] is True
def mock_client(self, session_name, response_code): """Mock a ControlClient object that has a predefined request response for an OpSession with the given name. Parameters: session_name (str): Name to give to the OpSession being called by ControlClient.request. response_code (int): Value of ResponseCode for the client.request call to return. """ session = create_session(session_name) encoded_session = session.encoded() client = MagicMock() client.request = MagicMock(return_value=(response_code, 'msg', encoded_session)) return client
def test_aggregator_agent_record_data(self, agent, tmpdir): # repoint data_dir to tmpdir fixture agent.data_dir = tmpdir agent.aggregate = True session = create_session('record') # inject some data to the queue data = generate_data_for_queue() agent._enqueue_incoming_data(data) params = {'test_mode': True} res = agent.record(session, params) assert res[0] is True assert 'current_file' in session.data assert 'providers' in session.data assert 'observatory.test-agent1.feeds.test_feed' in session.data['providers'] assert session.data['providers']['observatory.test-agent1.feeds.test_feed']['stale'] is False assert session.data['providers']['observatory.test-agent1.feeds.test_feed']['last_block_received'] == 'temps'
def encoded_session(self): session = create_session('test') encoded_session = session.encoded() return encoded_session
def test_aggregator_agent_stop_record_not_running(self, agent): session = create_session('record') # force session status to be 'done' session.set_status('done') res = agent._stop_record(session, params=None) assert res[0] is False
def test_aggregator_agent_stop_record_while_stopping(self, agent): session = create_session('record') session.set_status('stopping') res = agent._stop_record(session, params=None) assert res[0] is True
def test_aggregator_agent_stop_record_while_running(self, agent): session = create_session('record') agent.aggregate = True res = agent._stop_record(session, params=None) assert res[0] is True
def test_registry_register_agent(agent): session = create_session('main') agent_data = {'agent_address': 'observatory.test_agent'} res = agent._register_agent(session, agent_data) assert res[0] is True
def test_registry_stop_main_not_running(self, agent): session = create_session('main') res = agent._stop_main(session, params=None) assert res[0] is False
def test_fake_data_stop_acq_not_running(self, agent): session = create_session('acq') res = agent._stop_acq(session, params=None) assert res[0] is False
def test_influxdb_publisher_stop_record_while_stopping(self, agent): session = create_session('record') # force session status to be 'stopping' session.set_status('stopping') res = agent._stop_record(session, params=None) assert res[0] is True
def test_fake_data_delay_task(agent): session = create_session('delay_task') params = {'delay': 0.001, 'succeed': True} res = yield agent.delay_task(session, params=params) assert res[0] is True
def test_host_master_update_not_running(agent): session = create_session('update') res = agent.update(session, params=None) assert res[0] is False
def test_fake_data_set_heartbeat(agent): session = create_session('set_heartbeat') res = agent.set_heartbeat(session, {'heartbeat': True}) print(res) print(session.encoded()) assert res[0] is True