def testunit_handle_message_WHEN_type_IS_vs_xid_dlimits( self, mock_time, mock_get_xid_dlimits): mock_time.time.return_value = 10 mock_get_xid_dlimits.return_value = {'515': [386460, 10000000, 9533, -1, 2]} expected_value = ('{"message_type": "vs_xid_dlimits", "version": 1, "data":' ' {"515": [386460, 10000000, 9533, -1, 2]}, "ts": 10}') returned_value = vs_resource_backend.handle_message('vs_xid_dlimits') self.assertTrue(mock_get_xid_dlimits.called) self.assertEqual(returned_value, expected_value)
def testunit_handle_message_WHEN_type_IS_vs_xid_names( self, mock_time, mock_get_xid_names): mock_time.time.return_value = 10 mock_get_xid_names.return_value = {'515': 'mlab_utility'} expected_value = ('{"message_type": "vs_xid_names", "version": 1, "data":' ' {"515": "mlab_utility"}, "ts": 10}') returned_value = vs_resource_backend.handle_message('vs_xid_names') self.assertTrue(mock_get_xid_names.called) self.assertEqual(returned_value, expected_value)
def testunit_handle_message_WHEN_type_IS_backend_stats( self, mock_time, mock_get_backend_stats): mock_time.time.return_value = 10 mock_get_backend_stats.return_value = { 'rss': 2961408, 'vsize': 4919296, 'stime': 13.0, 'utime': 2.0} expected_value = ('{"message_type": "backend_stats", "version": 1, "data":' ' {"utime": 2.0, "vsize": 4919296, "stime": 13.0, ' '"rss": 2961408}, "ts": 10}') returned_value = vs_resource_backend.handle_message('backend_stats') self.assertTrue(mock_get_backend_stats.called) self.assertEqual(returned_value, expected_value)
def testunit_handle_message_WHEN_type_IS_unknown(self, mock_syslog_err): returned_value = vs_resource_backend.handle_message('unknown') self.assertTrue(mock_syslog_err.called) self.assertEqual(returned_value, None)