Correct summary bug in python wrapper 33/1133/5
authorE. Scott Daniels <daniels@research.att.com>
Thu, 10 Oct 2019 17:13:27 +0000 (13:13 -0400)
committerE. Scott Daniels <daniels@research.att.com>
Thu, 10 Oct 2019 18:09:53 +0000 (14:09 -0400)
The summary funciton in the python wrapper could have returned
a value which was not a dict type.

Added unit test to validate the receive all funciton in helpers.

Signed-off-by: E. Scott Daniels <daniels@research.att.com>
Change-Id: Ibed078b2a171fd3f8bd8bec51d4724e735337282

src/bindings/rmr-python/docs/Changelog.rst
src/bindings/rmr-python/rmr-version.yaml
src/bindings/rmr-python/rmr/rmr.py
src/bindings/rmr-python/setup.py
src/bindings/rmr-python/tests/fixtures/test_local.rt
src/bindings/rmr-python/tests/test_rmr.py

index b565641..3e353c3 100644 (file)
@@ -8,6 +8,14 @@ and this project adheres to `Semantic
 Versioning <http://semver.org/>`__.
 
 
+[0.13.3] - 10/10/2019
+--------------------
+
+::
+
+    * Add missing unit test for receive all.
+    * Correct bug in summary function.
+
 [0.13.2] - 10/2/2019
 --------------------
 
index 44d46c1..1ea7883 100644 (file)
@@ -1,3 +1,3 @@
 # CI script installs RMR from PackageCloud using this version
 ---
-version: 1.6.0
+version: 1.8.3
index 8c9ff5a..2ae40c8 100644 (file)
@@ -437,9 +437,6 @@ def message_summary(ptr_mbuf):
     dict:
         dict message summary
     """
-    if ptr_mbuf.contents.len > RMR_MAX_RCV_BYTES:
-        return "Malformed message: message length is greater than the maximum possible"
-
     return {
         "payload": get_payload(ptr_mbuf),
         "payload length": ptr_mbuf.contents.len,
index c1b3148..3f81a7d 100644 (file)
@@ -32,7 +32,7 @@ def _long_descr():
 
 setup(
     name="rmr",
-    version="0.13.2",
+    version="0.13.3",
     packages=find_packages(),
     author="Tommy Carpenter, E. Scott Daniels",
     description="Python wrapper for RIC RMR",
index 6250c45..bf49290 100644 (file)
@@ -1,3 +1,6 @@
+# do NOT use localhost, seems unresolved on jenkins VMs
 newrt|start
-rte|0|localhost:4563
+mse| 0 | -1 | 127.0.0.1:4563
+mse| 1 | -1 | 127.0.0.1:4564
+mse| 2 | -1 | 127.0.0.1:4564
 newrt|end
index dfc1364..172cc67 100644 (file)
@@ -17,7 +17,7 @@
 # ==================================================================================
 import time
 import pytest
-from rmr import rmr
+from rmr import rmr, helpers
 
 
 SIZE = 256
@@ -39,6 +39,10 @@ def setup_module():
     while rmr.rmr_ready(MRC_RCV) == 0:
         time.sleep(1)
 
+    global MRC_BUF_RCV
+    MRC_BUF_RCV = rmr.rmr_init(b"4564", rmr.RMR_MAX_RCV_BYTES, 0x02)
+    while rmr.rmr_ready(MRC_RCV) == 0:
+        time.sleep(1)
 
 def teardown_module():
     """
@@ -174,15 +178,18 @@ def test_send_rcv():
     sbuf_send.contents.mtype = 0
     sbuf_send = rmr.rmr_send_msg(MRC_SEND, sbuf_send)
     send_summary = rmr.message_summary(sbuf_send)
+    assert send_summary["message state"] == 0           # if send fails don't attempt receive
+    assert send_summary["message status"] == "RMR_OK"
+    time.sleep(.5)
 
     # receive it in other context
     sbuf_rcv = rmr.rmr_alloc_msg(MRC_RCV, SIZE)
     sbuf_rcv = rmr.rmr_torcv_msg(MRC_RCV, sbuf_rcv, 2000)
     rcv_summary = rmr.message_summary(sbuf_rcv)
-    assert rcv_summary["payload"] == pay
+    assert rcv_summary["message state"] == 0
+    assert rcv_summary["message status"] == "RMR_OK"
     assert rcv_summary["message type"] == 0
-    assert send_summary["message state"] == rcv_summary["message state"] == 0
-    assert send_summary["message status"] == rcv_summary["message status"] == "RMR_OK"
+    assert rcv_summary["payload"] == pay
 
     # send an ACK back
     ack_pay = b"message received"
@@ -194,6 +201,69 @@ def test_send_rcv():
     sbuf_send = rmr.rmr_torcv_msg(MRC_SEND, sbuf_send, 2000)
     send_ack_summary = rmr.message_summary(sbuf_send)
 
-    assert send_ack_summary["payload"] == ack_pay
     assert send_ack_summary["message state"] == rcv_ack_summary["message state"] == 0
     assert send_ack_summary["message status"] == rcv_ack_summary["message status"] == "RMR_OK"
+    assert send_ack_summary["payload"] == ack_pay
+
+
+def send_burst(mrc, fmt, mtype=1, num=13, counter=0):
+    """
+        Internal function to support test_rcv_all.
+        Send a burst of messages optionally giving the type, payload
+        and number to send.
+    """
+    sbuf_send = rmr.rmr_alloc_msg(MRC_SEND, SIZE)               # seed message buffer
+
+    for i in range(num):
+        payload = bytes(fmt % counter, "UTF-8")
+        counter += 1
+
+        rmr.set_payload_and_length(payload, sbuf_send)
+        sbuf_send.contents.mtype = mtype
+
+        max_retries = 5
+        while max_retries > 0:
+            sbuf_send = rmr.rmr_send_msg(mrc, sbuf_send)
+            ms = rmr.message_summary(sbuf_send)
+            if ms["message state"] != 10:                       # 10 is retry
+                break
+            max_retries -= 1
+            time.sleep(.75)
+
+        assert ms["message state"] == 0
+        assert max_retries > 0
+
+
+def test_rcv_all():
+    """
+    test the ability to receive a batch of queued messages. 
+    """
+    pay_fmt = "send to ring msg: %d"                # dynamic message format with counter
+
+    send_burst(MRC_SEND, pay_fmt)                   # send a bunch of 13 messages that should queue
+    time.sleep(1)                                        # ensure underlying transport gets cycles to send/receive
+
+    bundle = helpers.rmr_rcvall_msgs(MRC_BUF_RCV)        # use the buffered receiver to read all with a single call
+    assert len(bundle) == 13
+
+    for i in range(len(bundle)):
+        ms = bundle[i]                              # validate each summary returned, and ordering preserved
+        assert ms["message state"] == 0
+        expected_pay = bytes(pay_fmt % i, "UTF-8")
+        assert ms["payload"] == expected_pay
+
+    send_burst(MRC_SEND, pay_fmt, mtype=1, num=10)           # send a second round with msg types 1 and 2 to test filter
+    send_burst(MRC_SEND, pay_fmt, mtype=2, num=8)
+    send_burst(MRC_SEND, pay_fmt, mtype=1, num=5)
+    send_burst(MRC_SEND, pay_fmt, mtype=2, num=4, counter=8)    # total of 12 messages with type 2 should be queued
+    time.sleep(1)                                                    # ensure underlying transport gets cycles to send/receive
+
+    bundle = helpers.rmr_rcvall_msgs(MRC_BUF_RCV, [2])   # receive only message type 2 messages
+    assert len(bundle) == 12                        # we should only get the second batch of 12 messages
+
+    for i in range(len(bundle)):
+        ms = bundle[i]                              # validate each summary
+        assert ms["message state"] == 0             # all should be OK
+        assert ms["message type"] == 2              # only mtype 2 should have been received
+        expected_pay = bytes(pay_fmt % i, "UTF-8")           # ordering should still jive with the counter
+        assert ms["payload"] == expected_pay