Commit e40fcec6 authored by Waleed Akbar's avatar Waleed Akbar
Browse files

Enhance gNMI subscription handling and update test logging for dynamic durations

parent 421eda13
Loading
Loading
Loading
Loading
+14 −1
Original line number Original line Diff line number Diff line
@@ -112,9 +112,22 @@ class Subscription:
                    if update_msg.val.HasField("json_ietf_val"):
                    if update_msg.val.HasField("json_ietf_val"):
                        # Access raw bytes and decode directly (like pygnmi does)
                        # Access raw bytes and decode directly (like pygnmi does)
                        decoded_val = json.loads(update_msg.val.json_ietf_val)
                        decoded_val = json.loads(update_msg.val.json_ietf_val)
                        # Try to convert numeric strings to float for proper formatting
                        if isinstance(decoded_val, str):
                            try:
                                decoded_val = float(decoded_val)
                            except (ValueError, TypeError):
                                pass  # Keep as string if not numeric
                        update_container["val"] = decoded_val
                        update_container["val"] = decoded_val
                    elif update_msg.val.HasField("json_val"):
                    elif update_msg.val.HasField("json_val"):
                        update_container["val"] = json.loads(update_msg.val.json_val)
                        decoded_val = json.loads(update_msg.val.json_val)
                        # Try to convert numeric strings to float
                        if isinstance(decoded_val, str):
                            try:
                                decoded_val = float(decoded_val)
                            except (ValueError, TypeError):
                                pass
                        update_container["val"] = decoded_val
                    elif update_msg.val.HasField("string_val"):
                    elif update_msg.val.HasField("string_val"):
                        update_container["val"] = update_msg.val.string_val
                        update_container["val"] = update_msg.val.string_val
                    elif update_msg.val.HasField("int_val"):
                    elif update_msg.val.HasField("int_val"):
+8 −4
Original line number Original line Diff line number Diff line
@@ -129,16 +129,20 @@ def test_full_workflow(collector, subscription_data):
    logger.info("Subscription started: %s", subscription_data)
    logger.info("Subscription started: %s", subscription_data)
    assert all(response1) and isinstance(response1, list)
    assert all(response1) and isinstance(response1, list)


    _, _, duration_received, interval_received = subscription_data[0]
    
    # Get updates
    # Get updates
    logger.info("Requesting state updates for 5 seconds ...")
    logger.info(f"Requesting state updates for {duration_received} seconds after every {interval_received} seconds ...")
    updates_received = []
    updates_received = []
    for samples in collector.GetState(duration=5.0, blocking=True):
    for samples in collector.GetState(duration=duration_received, blocking=True):
        logger.info("Received state update: %s", samples)
        logger.info("Received state update: %s", samples)
        updates_received.append(samples)
        updates_received.append(samples)
    assert len(updates_received) > 0
    assert len(updates_received) > 0
    # Wait for additional updates
    # Wait for additional updates
    logger.info("Waiting for updates for 5 seconds...")
    logger.info(f"Waiting for updates after every {interval_received} seconds...")
    time.sleep(5)

    # put a sleep to simulate waiting for more updates
    time.sleep(15)
    
    
    # Unsubscribe
    # Unsubscribe
    response2 = collector.UnsubscribeState("x123")
    response2 = collector.UnsubscribeState("x123")