Skip to content

Commit

Permalink
issues/203: Bugfix - RuntimeError: Cannot call write() after write_eo…
Browse files Browse the repository at this point in the history
…f() (#208)

What:
- Bugfix - RuntimeError: Cannot call write() after write_eof()

Why:
- Fixes: #203
  • Loading branch information
komuw authored May 31, 2020
1 parent bf23bfe commit ccabab3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/_modules/naz/client.html
Original file line number Diff line number Diff line change
Expand Up @@ -2522,6 +2522,7 @@ <h1>Source code for naz.client</h1><div class="highlight"><pre>
<span class="k">async</span> <span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">drain_lock</span><span class="p">:</span>
<span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">drain</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">write_eof</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">writer</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">except</span> <span class="p">(</span>
<span class="ne">ConnectionError</span><span class="p">,</span>
<span class="ne">TimeoutError</span><span class="p">,</span>
Expand Down
1 change: 1 addition & 0 deletions naz/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit ccabab3

Please sign in to comment.