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

Mika Silander mika.silander at csc.fi
Wed Apr 14 08:57:12 CEST 2021


... after further debugging and torturing search engines it seems my "test problem" is a feature of the
unit test framework.

 By adding "import warnings" to the beginning of the test suite and then modifying the
test case to ignore ResourceWarnings :

def test_ok_events(self):

    warnings.simplefilter("ignore", ResourceWarning)

    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)

the test passes. If someone comes up with a better solution than this dirty work-around, please let me know.

Br, Mika

----- Original Message -----
From: "Mika Silander" <mika.silander at csc.fi>
To: "intelmq-dev" <intelmq-dev at lists.cert.at>
Sent: Tuesday, 13 April, 2021 17:40:41
Subject: [IntelMQ-dev] A spooky SSLSocket making tests fail?

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
_______________________________________________
IntelMQ-dev mailing list
https://lists.cert.at/cgi-bin/mailman/listinfo/intelmq-dev
https://intelmq.readthedocs.io/


More information about the IntelMQ-dev mailing list