Uploaded image for project: 'Data Collection, Analytics, and Events'
  1. Data Collection, Analytics, and Events
  2. DCAEGEN2-2953

improve code of heartbeat component

XMLWordPrintable

      in the dcaegen2/services/heartbeat repo, there are three modules with extremely poor code coverage by the tox tests:

      ```
      miss_htbt_service/db_monitoring.py 112 69 38%
      miss_htbt_service/htbtworker.py 147 116 21%
      miss_htbt_service/misshtbtd.py 319 154 52%
      ```
      Looking at the code, there are lots of short circuits within that are guarded by code similar to this:

      ``` python
        envPytest = os.getenv('pytest', "")
        if envPytest == 'test':
          break
      ```
      or
      ``` python
        if os.getenv('pytest', "") == 'test':
          do one thing
        else:
          do something else
      ```

      A lot of this code uses database calls, which the original writers probably had difficulty testing. However, the tests directory now has a mock module for the database library psycopg2, so all of this code should be able to be tested for real now using mocks. (If needed, the mock module can be enhanced for additional abilities.)

      Probably the only use of a test for $pytest would be to break out of an infinite loop within a function.

      ``` python
        while True:
          . . . code . . .
          if os.getenv('pytest', "") == 'test':
            break

      ```

       

      Jakarta code coverage is about 60% (https://sonarcloud.io/project/overview?id=onap_dcaegen2-services-heartbeat); Kohn target is 80%

            vv770d vv770d
            tonylhansen tonylhansen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: