|
1 | 1 | from __future__ import annotations |
| 2 | + |
| 3 | +import asyncio |
2 | 4 | from typing import List |
3 | 5 |
|
4 | 6 | import pytest |
@@ -96,12 +98,39 @@ async def test_write_multi_message_with_ack( |
96 | 98 | None, |
97 | 99 | ], |
98 | 100 | ) |
99 | | - async def test_write_encoded(self, driver: ydb.Driver, topic_path: str, codec): |
| 101 | + async def test_write_encoded(self, driver: ydb.aio.Driver, topic_path: str, codec): |
100 | 102 | async with driver.topic_client.writer(topic_path, codec=codec) as writer: |
101 | 103 | await writer.write("a" * 1000) |
102 | 104 | await writer.write("b" * 1000) |
103 | 105 | await writer.write("c" * 1000) |
104 | 106 |
|
| 107 | + async def test_create_writer_after_stop(self, driver: ydb.aio.Driver, topic_path: str): |
| 108 | + await driver.stop() |
| 109 | + with pytest.raises(ydb.Error): |
| 110 | + async with driver.topic_client.writer(topic_path) as writer: |
| 111 | + await writer.write_with_ack("123") |
| 112 | + |
| 113 | + async def test_send_message_after_stop(self, driver: ydb.aio.Driver, topic_path: str): |
| 114 | + writer = driver.topic_client.writer(topic_path) |
| 115 | + await driver.stop() |
| 116 | + with pytest.raises(ydb.Error): |
| 117 | + await writer.write_with_ack("123") |
| 118 | + |
| 119 | + async def test_preserve_exception_on_cm_close(self, driver: ydb.aio.Driver, topic_path: str): |
| 120 | + class TestException(Exception): |
| 121 | + pass |
| 122 | + |
| 123 | + with pytest.raises(TestException): |
| 124 | + async with driver.topic_client.writer(topic_path) as writer: |
| 125 | + await writer.wait_init() |
| 126 | + await driver.stop() # will raise exception on topic writer __exit__ |
| 127 | + |
| 128 | + # ensure writer has exception internally |
| 129 | + with pytest.raises((ydb.Error, asyncio.CancelledError)): |
| 130 | + await writer.write_with_ack("123") |
| 131 | + |
| 132 | + raise TestException() |
| 133 | + |
105 | 134 |
|
106 | 135 | class TestTopicWriterSync: |
107 | 136 | def test_send_message(self, driver_sync: ydb.Driver, topic_path): |
@@ -212,3 +241,30 @@ def test_start_many_sync_writers_in_parallel(self, driver_sync: ydb.Driver, topi |
212 | 241 |
|
213 | 242 | for writer in writers: |
214 | 243 | writer.close() |
| 244 | + |
| 245 | + def test_create_writer_after_stop(self, driver_sync: ydb.Driver, topic_path: str): |
| 246 | + driver_sync.stop() |
| 247 | + with pytest.raises(ydb.Error): |
| 248 | + with driver_sync.topic_client.writer(topic_path) as writer: |
| 249 | + writer.write_with_ack("123") |
| 250 | + |
| 251 | + def test_send_message_after_stop(self, driver_sync: ydb.Driver, topic_path: str): |
| 252 | + writer = driver_sync.topic_client.writer(topic_path) |
| 253 | + driver_sync.stop() |
| 254 | + with pytest.raises(ydb.Error): |
| 255 | + writer.write_with_ack("123") |
| 256 | + |
| 257 | + def test_preserve_exception_on_cm_close(self, driver_sync: ydb.Driver, topic_path: str): |
| 258 | + class TestException(Exception): |
| 259 | + pass |
| 260 | + |
| 261 | + with pytest.raises(TestException): |
| 262 | + with driver_sync.topic_client.writer(topic_path) as writer: |
| 263 | + writer.wait_init() |
| 264 | + driver_sync.stop() # will raise exception on topic writer __exit__ |
| 265 | + |
| 266 | + # ensure writer has exception internally |
| 267 | + with pytest.raises(ydb.Error): |
| 268 | + writer.write_with_ack("123") |
| 269 | + |
| 270 | + raise TestException() |
0 commit comments