[IntelMQ-dev] A spooky SSLSocket making tests fail?

Mika Silander mika.silander at csc.fi
Tue Apr 13 16:40:41 CEST 2021


Hi,

 Something fails in my unit tests for my output bot: I have a test following this outline:

def test_ok_events(self):

    for event in [ firstevent, secondevent ]:
        self.input_message = event
        self.run_bot(parameters={ 'logging_level': 'DEBUG', ... some other bot specific parameters here ... },
                                  iterations=1, allowed_error_count=0, allowed_warning_count=0)

Above firstevent and secondevent are JSON structures that conform to the Event class.
The first event is handled ok, but the second seems to get handled but in the end
the run_bot method in /opt/dev_intelmq/intelmq/lib/test.py claims things are not ok.

Next, I raise allowed_warning_count to 4 (other bot parameters remain untouched) and the same thing
happens although the bot progresses a bit further down the run_bot method and then prints the
following traceback message in my IDE's console: 

---

Failure
Traceback (most recent call last):
  File "/opt/dev_intelmq/intelmq/tests/bots/outputs/mybot/test_output.py", line ABC, in test_ok_events
    }, allowed_warning_count=4)
  File "/opt/dev_intelmq/intelmq/lib/test.py, line 356, in run_bot
    ''.format(fields['message']))
AssertionError: False is not true : Logline "/opt/dev_intelmq/intelmq/lib/test.py:232: ResourceWarning: unclosed <ssl.SSLSocket ... >" does not end with .? or !.

---

I guess the unclosed socket is due to my bot using Sessions from the requests module to send data
to a back end service and this is not taken down between the two invocations of the run_bot method.

Any ideas how I should modify the test to take this session down before the second event is tested?
Or, maybe better still, how should I modify my bot to close this session down cleanly at exit?
By overriding a suitable stop or shutdown method and closing the session inside this overriding method?

Thanks again, Mika


More information about the IntelMQ-dev mailing list