Checking Pub / Sub Batch.will_accept in thread-safe way.#4616
Checking Pub / Sub Batch.will_accept in thread-safe way.#4616dhermes merged 3 commits intogoogleapis:masterfrom
Batch.will_accept in thread-safe way.#4616Conversation
| # in a separate thread. | ||
|
|
||
| # Sleep for however long we should be waiting. | ||
| time.sleep(self._settings.max_latency) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
|
||
| def test_publish_max_messages(): | ||
| batch = create_batch(max_messages=4) | ||
| def test_publish_not_will_accept(): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| # If this message will make the batch exceed the ``max_bytes`` | ||
| # setting, return False. | ||
| if self.size + message.ByteSize() > self.settings.max_bytes: | ||
| if self.size + message.ByteSize() >= self.settings.max_bytes: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| f = futures.Future() | ||
| self._futures.append(f) | ||
| return f | ||
| return future |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| name='Thread-CommitBatchPublisher', | ||
| target=batch._commit, | ||
| ) | ||
| Thread.return_value.start.assert_called_once_with() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Unit tests will be coming in the next commit. Fixes googleapis#4575.
- Changing back `>=` to `>` (I was misreading a `curr_size + EXTRA > MAX` as `curr_size > MAX`) - Putting `assert_*()` calls on `Thread` mock back in the context manager
435cd08 to
cbaea8b
Compare
Unit tests will be coming in the next commit.
Fixes #4575.