Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion solrorbit/worker_coordinator/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,10 +1526,12 @@ def __str__(self):
# Runner: raw-request
# ---------------------------------------------------------------------------

class RawRequest(Runner):
class RawRequest(SolrRunner):
"""
Send an arbitrary HTTP request to any Solr endpoint.

A 4xx or 5xx response is reported as a failed request, like the other runners.

Params:
- ``method`` (default "GET"), ``path``, ``body``, ``headers``
"""
Expand All @@ -1544,6 +1546,9 @@ async def __call__(self, client, params):
start = time.perf_counter()
resp = await _run_in_executor(sc.raw_request, method, path, body, headers)
elapsed = time.perf_counter() - start
# raw_request returns error responses instead of raising; SolrRunner turns this
# HTTPError into a BenchmarkTransportError, so the request counts as an error.
resp.raise_for_status()

return {
"weight": 1,
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/solr/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
import unittest
from unittest.mock import MagicMock

import requests

from solrorbit import exceptions
from solrorbit.worker_coordinator.runner import (
RawRequest,
_translate_ndjson_batch,
SolrBulkIndex,
SolrOptimize,
Expand Down Expand Up @@ -435,5 +439,31 @@ def test_search_via_framework(self):
self.assertEqual(5, result["hits"])


class TestRawRequest(unittest.TestCase):
@staticmethod
def _client(status_code):
resp = requests.Response()
resp.status_code = status_code
resp.url = "http://localhost:8983/api/collections/test"
mock_sc = MagicMock()
mock_sc.raw_request.return_value = resp
return mock_sc

def test_success_reports_http_status(self):
result = _run(RawRequest()(self._client(200), {"path": "/api/collections/test"}))
self.assertEqual(200, result["http-status"])
self.assertEqual(1, result["weight"])

def test_server_error_is_a_transport_error(self):
"""A rejected request must count as an error, not as a successful operation."""
with self.assertRaises(exceptions.BenchmarkTransportError) as ctx:
_run(RawRequest()(self._client(500), {"path": "/api/collections/test", "method": "POST"}))
self.assertEqual(500, ctx.exception.status_code)

def test_not_found_is_a_transport_error(self):
with self.assertRaises(exceptions.BenchmarkNotFoundError):
_run(RawRequest()(self._client(404), {"path": "/api/collections/missing"}))


if __name__ == "__main__":
unittest.main()
Loading