Skip to content

Commit

Permalink
Update Python MockSession
Browse files Browse the repository at this point in the history
The `MockSession` class in the Python SDK is used by our test suite to ensure
that session options are properly propagated through our Cython layer so they
can be passed to libbmq.  However, because have introduced new session options
into the Python SDK, the `MockSession` class needs to be updated so it knows
about these additional options.  This patch extends `MockSession` with the new
session options.

Signed-off-by: Patrick M. Niedzielski <[email protected]>
  • Loading branch information
pniedzielski committed Nov 29, 2023
1 parent 020f942 commit 1f51f7e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/cpp/pybmq_mocksession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,29 +276,52 @@ MockSession::MockSession(
static const char* const option_names[] = {
"broker_uri",
"process_name_override",
"connect_timeout",
"disconnect_timeout",
"open_queue_timeout",
"configure_queue_timeout",
"close_queue_timeout"};

"close_queue_timeout",
"num_processing_threads",
"blob_buffer_size",
"channel_high_watermark",
"event_queue_low_watermark",
"event_queue_high_watermark",
"stats_dump_interval"};

double timeout_connect_secs = options.connectTimeout().seconds()
+ options.connectTimeout().nanoseconds() * 1e-9;
double timeout_disconnect_secs = options.disconnectTimeout().seconds()
+ options.disconnectTimeout().nanoseconds() * 1e-9;
double timeout_open_secs = options.openQueueTimeout().seconds()
+ options.openQueueTimeout().nanoseconds() * 1e-9;
double timeout_configure_secs =
options.configureQueueTimeout().seconds()
+ options.configureQueueTimeout().nanoseconds() * 1e-9;
double timeout_close_secs = options.closeQueueTimeout().seconds()
+ options.closeQueueTimeout().nanoseconds() * 1e-9;
double stats_dump_interval_secs =
options.statsDumpInterval().seconds()
+ options.statsDumpInterval().nanoseconds() * 1e-9;

bslma::ManagedPtr<PyObject> py_options = RefUtils::toManagedPtr(_Py_DictBuilder(
option_names,
"(s# N f f f)",
"(s# N f f f f f i i i i i f)",
options.brokerUri().c_str(),
options.brokerUri().length(),
PyBytes_FromStringAndSize(
options.processNameOverride().c_str(),
options.processNameOverride().length()),
timeout_connect_secs,
timeout_disconnect_secs,
timeout_open_secs,
timeout_configure_secs,
timeout_close_secs));
timeout_close_secs,
options.numProcessingThreads(),
options.blobBufferSize(),
options.channelHighWatermark(),
options.eventQueueLowWatermark(),
options.eventQueueHighWatermark(),
stats_dump_interval_secs));
if (!py_options) throw bsl::runtime_error("propagating Python error");
PyObject_SetAttrString(d_mock, "options", py_options.get());
}
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_ext_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,36 @@ def test_session_timeout_passed_to_queue_defaults():
assert mock.options["close_queue_timeout"] == close_queue_timeout


def test_session_session_options_propagated():
# GIVEN
mock = sdk_mock(start=0, stop=None)
num_processing_threads = 10
blob_buffer_size = 5000
channel_high_watermark = 20000000
event_queue_low_watermark = 1000000
event_queue_high_watermark = 10000000
stats_dump_interval = 90.0

# WHEN
Session(
dummy_callback,
num_processing_threads=num_processing_threads,
blob_buffer_size=blob_buffer_size,
channel_high_watermark=channel_high_watermark,
event_queue_watermarks=(event_queue_low_watermark, event_queue_high_watermark),
stats_dump_interval=stats_dump_interval,
_mock=mock,
)

# THEN
assert mock.options["num_processing_threads"] == num_processing_threads
assert mock.options["blob_buffer_size"] == blob_buffer_size
assert mock.options["channel_high_watermark"] == channel_high_watermark
assert mock.options["event_queue_low_watermark"] == event_queue_low_watermark
assert mock.options["event_queue_high_watermark"] == event_queue_high_watermark
assert mock.options["stats_dump_interval"] == stats_dump_interval


def test_ensure_stop_session_callback_calls_sdk_stop():
"""Ensure that every started session is stopped by `ensure_stop_session`.
Expand Down

0 comments on commit 1f51f7e

Please sign in to comment.