From ccabab30b415ccccea4b04ca25ccf57ef09007bb Mon Sep 17 00:00:00 2001 From: Komu Wairagu Date: Sun, 31 May 2020 11:00:15 +0300 Subject: [PATCH] issues/203: Bugfix - RuntimeError: Cannot call write() after write_eof() (#208) What: - Bugfix - RuntimeError: Cannot call write() after write_eof() Why: - Fixes: https://github.com/komuw/naz/issues/203 --- CHANGELOG.md | 1 + docs/_modules/naz/client.html | 1 + naz/client.py | 1 + tests/test_client.py | 23 +++++++++++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 148c4be6..876eb504 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ most recent version is listed first. ## **version:** v0.8.0 +- Bugfix - RuntimeError: Cannot call `write()` after `write_eof()`: https://github.com/komuw/naz/pull/208 - support Smpp Optional Tags in `submit_sm`: https://github.com/komuw/naz/pull/202, https://github.com/komuw/naz/pull/207 - Fixed some flaky tests: https://github.com/komuw/naz/pull/204, https://github.com/komuw/naz/pull/206 - Add ability to use different codecs for different messages while using the same `naz` client: https://github.com/komuw/naz/pull/201 diff --git a/docs/_modules/naz/client.html b/docs/_modules/naz/client.html index 6f7c0733..2bf05b8f 100644 --- a/docs/_modules/naz/client.html +++ b/docs/_modules/naz/client.html @@ -2522,6 +2522,7 @@

Source code for naz.client

             async with self.drain_lock:
                 await self.writer.drain()
             self.writer.write_eof()
+            self.writer = None
         except (
             ConnectionError,
             TimeoutError,
diff --git a/naz/client.py b/naz/client.py
index 5b87d196..91c13fe5 100644
--- a/naz/client.py
+++ b/naz/client.py
@@ -2357,6 +2357,7 @@ async def _unbind_and_disconnect(self):
             async with self.drain_lock:
                 await self.writer.drain()
             self.writer.write_eof()
+            self.writer = None
         except (
             ConnectionError,
             TimeoutError,
diff --git a/tests/test_client.py b/tests/test_client.py
index 7ce23f43..16587b40 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -1072,3 +1072,26 @@ def test_send_message_with_more_args(self):
                 mock_naz_enqueue.mock.call_args[0][1].smpp_command, naz.SmppCommand.SUBMIT_SM
             )
             self.assertEqual(mock_naz_enqueue.mock.call_args[0][1].short_message, short_message)
+
+    def test_issues_203(self):
+        """
+        test to prove we have fixed: https://github.com/komuw/naz/issues/203
+
+        1. connect to smsc
+        2. bind
+        3. unbind & disconnect
+        4. send `submit_sm`
+        """
+        self._run(self.cli.connect())
+        self._run(self.cli.tranceiver_bind())
+        self.assertIsNotNone(self.cli.writer)
+
+        self._run(self.cli._unbind_and_disconnect())
+        self.assertIsNone(self.cli.writer)
+
+        self._run(
+            self.cli.send_data(
+                smpp_command=naz.SmppCommand.SUBMIT_SM, msg=b"someMessage", log_id="log_id"
+            )
+        )
+        self.assertIsNotNone(self.cli.writer)