# Buggy code
def check_resources(self):
    """
    Check CPU and memory usage.
    """
    self._logger.debug("Checking memory/CPU usage")
    if len(self.cpu_data) == self.history_size:
        self.cpu_data.pop(0)
    if len(self.memory_data) == self.history_size:
        self.memory_data.pop(0)

    time_seconds = time.time()
    self.cpu_data.append((time_seconds, self.process.cpu_percent(interval=None)))
    self.memory_data.append((time_seconds, self.process.memory_full_info().uss))


# Traceback (AssertionError)
Tuples differ: (2, ('127.0.0.1', [5, 4, 3, 2,... != (2, ('127.0.0.1', [5, 4, 3, 2,...

First differing element 2:
u'None'
''

- (2, ('127.0.0.1', [5, 4, 3, 2, 1]), u'None')
?                                     - ----

+ (2, ('127.0.0.1', [5, 4, 3, 2, 1]), '')
Stacktrace

Traceback (most recent call last):
File "c:\python27\lib\unittest\case.py", line 329, in run
testMethod()
File "C:\workspace\jenkins\workspace\GH_Tribler_PR_tests_win64\tribler\Tribler\Test\test_as_server.py", line 58, in check
result = fun(*argv, **kwargs)
File "C:\workspace\jenkins\workspace\GH_Tribler_PR_tests_win64\tribler\Tribler\Test\Core\Upgrade\test_config_upgrade_70_71.py", line 33, in test_read_test_libtribler_conf
self.assertEqual(result_config.get_anon_proxy_settings(), (2, ("127.0.0.1", [5, 4, 3, 2, 1]), ''))
File "c:\python27\lib\unittest\case.py", line 513, in assertEqual
assertion_func(first, second, msg=msg)
File "c:\python27\lib\unittest\case.py", line 753, in assertTupleEqual
self.assertSequenceEqual(tuple1, tuple2, msg, seq_type=tuple)
File "c:\python27\lib\unittest\case.py", line 724, in assertSequenceEqual
self.fail(msg)
File "c:\python27\lib\unittest\case.py", line 410, in fail
raise self.failureException(msg)
AssertionError: Tuples differ: (2, ('127.0.0.1', [5, 4, 3, 2,... != (2, ('127.0.0.1', [5, 4, 3, 2,...

First differing element 2:
u'None'
''

- (2, ('127.0.0.1', [5, 4, 3, 2, 1]), u'None')
?                                     - ----

+ (2, ('127.0.0.1', [5, 4, 3, 2, 1]), '')

# Fixed code
def check_resources(self):
    """
    Check CPU and memory usage.
    """
    self._logger.debug("Checking memory/CPU usage")
    if len(self.cpu_data) == self.history_size:
        self.cpu_data.pop(0)
    if len(self.memory_data) == self.history_size:
        self.memory_data.pop(0)

    time_seconds = time.time()
    self.cpu_data.append((time_seconds, self.process.cpu_percent(interval=None)))

    # Get the memory usage of the process
    # psutil package 4.0.0 introduced memory_full_info() method which among other info also returns uss.
    # uss (Unique Set Size) is probably the most representative metric for determining how much memory is
    # actually being used by a process.
    # However, on psutil version < 4.0.0, we fallback to use rss (Resident Set Size) which is the non-swapped
    # physical memory a process has used
    if hasattr(self.process, "memory_full_info") and callable(
        getattr(self.process, "memory_full_info")
    ):
        self.memory_data.append((time_seconds, self.process.memory_full_info().uss))
    elif hasattr(self.process, "memory_info") and callable(
        getattr(self.process, "memory_info")
    ):
        self.memory_data.append((time_seconds, self.process.memory_info().rss))