Skip to content

Commit 370b7e3

Browse files
committedSep 26, 2023
fix: drop first info event without a version
closes #55
1 parent 75a0b57 commit 370b7e3

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed
 

‎run_tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if [ $version ]
55
then
66
versions=("$version")
77
else
8-
versions=(1.23.1 1.23.0 1.22.1 1.22.0 1.21.3)
8+
versions=(1.23.2 1.23.0 1.22.1 1.22.0 1.21.3)
99
fi
1010

1111
for version in ${versions[*]}

‎tests/test_info.py

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import unittest
22

3+
from uptime_kuma_api import UptimeKumaApi
34
from uptime_kuma_test_case import UptimeKumaTestCase
45

56

@@ -9,6 +10,16 @@ def test_info(self):
910
self.assertIn("version", info)
1011
self.assertIn("latestVersion", info)
1112

13+
def test_info_with_version(self):
14+
# If wait_events is set to 0, the first info event is normally used.
15+
# The info event handler needs to drop this first event without a version.
16+
self.api.logout()
17+
self.api.disconnect()
18+
self.api = UptimeKumaApi(self.url, wait_events=0)
19+
self.api.login(self.username, self.password)
20+
info = self.api.info()
21+
self.assertIn("version", info)
22+
1223

1324
if __name__ == '__main__':
1425
unittest.main()

‎uptime_kuma_api/api.py

+3
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,9 @@ def _event_heartbeat(self, data) -> None:
626626
self._event_data[Event.IMPORTANT_HEARTBEAT_LIST][monitor_id] = [data] + self._event_data[Event.IMPORTANT_HEARTBEAT_LIST][monitor_id]
627627

628628
def _event_info(self, data) -> None:
629+
if "version" not in data:
630+
# wait for the info event that is sent after login and contains the version
631+
return
629632
self._event_data[Event.INFO] = data
630633

631634
def _event_cert_info(self, monitor_id, data) -> None:

0 commit comments

Comments
 (0)
Please sign in to comment.