facebook / openbmc

OpenBMC is an open software framework to build a complete Linux image for a Board Management Controller (BMC).
633 stars 277 forks source link

Fix sensors unit test #171

Closed xaionaro closed 2 years ago

xaionaro commented 2 years ago

Summary

It appears snr.getInformation() sometimes returns a value, but sometimes a coroutine (to calculate the value). So conditionally executing the coroutine if required.

Test Plan

How to test

Executed:

./tools/rest_api/rest_test_loop

and stopped, copied generated run.do_unit_test to /tmp and modified the path from

/data/users/xaionaro/openbmc/meta-facebook/meta-fby2/meta-fby2-nd/tmp/work/x86_64-linux/rest-api-native/0.1-r1

to

common/recipes-rest/rest-api/files

Then executed /tmp/run.do_unit_test

Before

/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/site-packages/aiohttp/helpers.py:141: PendingDeprecationWarning: Task.current_task() is deprecated, use asyncio.current_task() instead
  task = asyncio.Task.current_task(loop=loop)
.Task was destroyed but it is pending!
task: <Task pending coro=<AsyncRateLimiter._cleanup() done, defined at /data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/async_ratelimiter.py:54> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f440b9f7650>()]>>
Task was destroyed but it is pending!
task: <Task pending coro=<AsyncRateLimiter._cleanup() done, defined at /data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/async_ratelimiter.py:54> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f440b9f78d0>()]>>
Task was destroyed but it is pending!
task: <Task pending coro=<AsyncRateLimiter._cleanup() done, defined at /data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/async_ratelimiter.py:54> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f440ba1a610>()]>>
./data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/test_async_ratelimiter.py:88: RuntimeWarning: coroutine 'TestRatelimiterWorks.__assert_normal_request' was never awaited
  self.__assert_normal_request("GET", "agent2")
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Task was destroyed but it is pending!
task: <Task pending coro=<AsyncRateLimiter._cleanup() running at /data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/async_ratelimiter.py:55> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f440b9f7390>()]>>
Task was destroyed but it is pending!
task: <Task pending coro=<AsyncRateLimiter._cleanup() running at /data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/async_ratelimiter.py:55> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f440ba1a790>()]>>
.Task was destroyed but it is pending!
task: <Task pending coro=<AsyncRateLimiter._cleanup() done, defined at /data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/async_ratelimiter.py:54> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f440b9f7750>()]>>
Task was destroyed but it is pending!
task: <Task pending coro=<AsyncRateLimiter._cleanup() done, defined at /data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/async_ratelimiter.py:54> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f440ba1aed0>()]>>
............../data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/asyncio/base_events.py:626: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False>
  source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
......................................./data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/site-packages/multidict/_multidict_py.py:165: ResourceWarning: unclosed file <_io.FileIO name='/tmp/tmptc21d7sw' mode='ab' closefd=True>
  self._items = []
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/site-packages/multidict/_multidict_py.py:165: ResourceWarning: unclosed <socket.socket fd=5, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_DGRAM, proto=0, raddr=/run/systemd/journal/dev-log>
  self._items = []
ResourceWarning: Enable tracemalloc to get the object allocation traceback
..F/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/unittest/case.py:656: RuntimeWarning: coroutine 'sensorsNode.getInformation' was never awaited
  outcome.errors.clear()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
FFF......................................................
======================================================================
FAIL: test_basic_call (test_node_sensors.TestSensors)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/unittest/mock.py", line 1256, in patched
    return func(*args, **keywargs)
  File "/data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/test_node_sensors.py", line 28, in test_basic_call
    self.assertEqual(snr.getInformation(), expected_full_output)
AssertionError: <coroutine object sensorsNode.getInformation at 0x7f440b9d4b00> != {'MB_INLET_TEMP': {'value': '33.31'}, 'MB_OUTLET_TEMP': {'value': '29.56'}}

======================================================================
FAIL: test_filter_by_id_call (test_node_sensors.TestSensors)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/unittest/mock.py", line 1256, in patched
    return func(*args, **keywargs)
  File "/data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/test_node_sensors.py", line 72, in test_filter_by_id_call
    snr.getInformation(param={"id": "0xA0"}), expected_filtered_output
AssertionError: <coroutine object sensorsNode.getInformation at 0x7f440b9ed440> != {'MB_INLET_TEMP': {'value': '33.31'}}

======================================================================
FAIL: test_history_call (test_node_sensors.TestSensors)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/unittest/mock.py", line 1256, in patched
    return func(*args, **keywargs)
  File "/data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/test_node_sensors.py", line 135, in test_history_call
    expected_filtered_output,
AssertionError: <coroutine object sensorsNode.getInformation at 0x7f440b9ed3b0> != {'MB_INLET_TEMP': {'min': '32.88', 'avg': '32.88', 'max': '32.88'}}

======================================================================
FAIL: test_thresholds_call (test_node_sensors.TestSensors)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/unittest/mock.py", line 1256, in patched
    return func(*args, **keywargs)
  File "/data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/test_node_sensors.py", line 102, in test_thresholds_call
    expected_no_thresholds_sensor,
AssertionError: <coroutine object sensorsNode.getInformation at 0x7f440b9ed4d0> != {'MB_INLET_TEMP': {'value': '32.62'}}

----------------------------------------------------------------------
Ran 116 tests in 0.898s

FAILED (failures=4)
WARNING: /tmp/run.do_unit_test:1 exit 1 from 'python3 -m unittest discover $@'

After

/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/site-packages/aiohttp/helpers.py:141: PendingDeprecationWarning: Task.current_task() is deprecated, use asyncio.current_task() instead
  task = asyncio.Task.current_task(loop=loop)
.Task was destroyed but it is pending!
task: <Task pending coro=<AsyncRateLimiter._cleanup() done, defined at /data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/async_ratelimiter.py:54> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f4b75d59650>()]>>
Task was destroyed but it is pending!
task: <Task pending coro=<AsyncRateLimiter._cleanup() done, defined at /data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/async_ratelimiter.py:54> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f4b759fa490>()]>>
Task was destroyed but it is pending!
task: <Task pending coro=<AsyncRateLimiter._cleanup() done, defined at /data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/async_ratelimiter.py:54> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f4b759fa510>()]>>
./data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/test_async_ratelimiter.py:88: RuntimeWarning: coroutine 'TestRatelimiterWorks.__assert_normal_request' was never awaited
  self.__assert_normal_request("GET", "agent2")
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Task was destroyed but it is pending!
task: <Task pending coro=<AsyncRateLimiter._cleanup() running at /data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/async_ratelimiter.py:55> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f4b75d59cd0>()]>>
Task was destroyed but it is pending!
task: <Task pending coro=<AsyncRateLimiter._cleanup() running at /data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/async_ratelimiter.py:55> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f4b759fa2d0>()]>>
.Task was destroyed but it is pending!
task: <Task pending coro=<AsyncRateLimiter._cleanup() done, defined at /data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/async_ratelimiter.py:54> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f4b75d59a10>()]>>
Task was destroyed but it is pending!
task: <Task pending coro=<AsyncRateLimiter._cleanup() done, defined at /data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/async_ratelimiter.py:54> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f4b759fae10>()]>>
............../data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/asyncio/base_events.py:626: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False>
  source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
......................................./data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/site-packages/multidict/_multidict_py.py:191: ResourceWarning: unclosed file <_io.FileIO name='/tmp/tmpjb08_k6p' mode='ab' closefd=True>
  if isinstance(args[0], MultiDictProxy):
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/site-packages/multidict/_multidict_py.py:191: ResourceWarning: unclosed <socket.socket fd=5, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_DGRAM, proto=0, raddr=/run/systemd/journal/dev-log>
  if isinstance(args[0], MultiDictProxy):
ResourceWarning: Enable tracemalloc to get the object allocation traceback
..FF/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/asyncio/base_subprocess.py:126: ResourceWarning: unclosed transport <_UnixSubprocessTransport pid=<Mock name='Popen().pid' id='139962072837136'> running>
  source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/asyncio/unix_events.py:723: ResourceWarning: unclosed transport <_UnixWritePipeTransport fd=<Mock name='Popen().stdin.fileno()' id='139962072837904'> open>
  source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/asyncio/base_subprocess.py:126: ResourceWarning: unclosed transport <_UnixSubprocessTransport pid=<Mock name='Popen().pid' id='139962167987216'> running>
  source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/asyncio/unix_events.py:723: ResourceWarning: unclosed transport <_UnixWritePipeTransport fd=<Mock name='Popen().stdin.fileno()' id='139962072813776'> open>
  source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
F/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/asyncio/base_subprocess.py:126: ResourceWarning: unclosed transport <_UnixSubprocessTransport pid=<Mock name='Popen().pid' id='139962071594896'> running>
  source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/asyncio/unix_events.py:723: ResourceWarning: unclosed transport <_UnixWritePipeTransport fd=<Mock name='Popen().stdin.fileno()' id='139962071595344'> open>
  source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
F/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/asyncio/base_subprocess.py:126: ResourceWarning: unclosed transport <_UnixSubprocessTransport pid=<Mock name='Popen().pid' id='139962071630288'> running>
  source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/asyncio/unix_events.py:723: ResourceWarning: unclosed transport <_UnixWritePipeTransport fd=<Mock name='Popen().stdin.fileno()' id='139962071594256'> open>
  source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
...............................................................Exception  received
Cannot add child handler, the child watcher does not have a loop attached
Exception  received
Cannot add child handler, the child watcher does not have a loop attached
Exception  received
Cannot add child handler, the child watcher does not have a loop attached
Exception  received
Cannot add child handler, the child watcher does not have a loop attached

======================================================================
FAIL: test_basic_call (test_node_sensors.TestSensors)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/unittest/mock.py", line 1256, in patched
    return func(*args, **keywargs)
  File "/data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/test_node_sensors.py", line 41, in test_basic_call
    self.assertEqual(await_if_required(snr.getInformation()), expected_full_output)
AssertionError: [] != {'MB_INLET_TEMP': {'value': '33.31'}, 'MB_OUTLET_TEMP': {'value': '29.56'}}

======================================================================
FAIL: test_filter_by_id_call (test_node_sensors.TestSensors)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/unittest/mock.py", line 1256, in patched
    return func(*args, **keywargs)
  File "/data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/test_node_sensors.py", line 86, in test_filter_by_id_call
    expected_filtered_output,
AssertionError: [] != {'MB_INLET_TEMP': {'value': '33.31'}}

======================================================================
FAIL: test_history_call (test_node_sensors.TestSensors)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/unittest/mock.py", line 1256, in patched
    return func(*args, **keywargs)
  File "/data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/test_node_sensors.py", line 155, in test_history_call
    expected_filtered_output,
AssertionError: [] != {'MB_INLET_TEMP': {'min': '32.88', 'avg': '32.88', 'max': '32.88'}}

======================================================================
FAIL: test_thresholds_call (test_node_sensors.TestSensors)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/users/xaionaro/openbmc/build-fbnd/tmp/work/x86_64-linux/rest-api-native/0.1-r1/recipe-sysroot-native/usr/lib/python3.7/unittest/mock.py", line 1256, in patched
    return func(*args, **keywargs)
  File "/data/users/xaionaro/openbmc/common/recipes-rest/rest-api/files/test_node_sensors.py", line 118, in test_thresholds_call
    expected_no_thresholds_sensor,
AssertionError: [] != {'MB_INLET_TEMP': {'value': '32.62'}}

----------------------------------------------------------------------
Ran 125 tests in 1.474s

FAILED (failures=4)
WARNING: /tmp/run.do_unit_test:1 exit 1 from 'python3 -m unittest discover $@'

In total

Before:

Ran 116 tests in 0.898s

After:

Ran 125 tests in 1.474s

Error samples

Before:

AssertionError: <coroutine object sensorsNode.getInformation at 0x7f440b9ed4d0> != {'MB_INLET_TEMP': {'value': '32.62'}}

After:

AssertionError: [] != {'MB_INLET_TEMP': {'value': '32.62'}}
facebook-github-bot commented 2 years ago

This pull request was exported from Phabricator. Differential Revision: D31840645

xaionaro commented 2 years ago

Tests seem to fail not due to the changes (if I read the log correctly).