Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests using volttron-testing #11

Open
bonicim opened this issue Jul 13, 2022 · 1 comment
Open

Add tests using volttron-testing #11

bonicim opened this issue Jul 13, 2022 · 1 comment
Assignees

Comments

@bonicim
Copy link
Contributor

bonicim commented Jul 13, 2022

No description provided.

@bonicim bonicim self-assigned this Jul 13, 2022
@bonicim bonicim moved this to Todo in Modularization Board Jul 13, 2022
@bonicim bonicim changed the title Update README Add tests, update README Jul 15, 2022
@bonicim bonicim changed the title Add tests, update README Add tests using volttron-testing Jul 25, 2022
@bonicim bonicim moved this from Todo to In Progress in Modularization Board Jul 25, 2022
@bonicim bonicim moved this from In Progress to Todo in Modularization Board Jul 25, 2022
@kefeimo
Copy link

kefeimo commented Mar 15, 2023

One potential solution is to use the volttron-testing's TestServer (from volttrontesting.server_mock import TestServer)

So that, we can do things like the following

def test_send_alert():
    """ Test that an agent can send an alert through the pubsub message bus."""

    # Create an agent to run the test with
    # agent = Agent(identity='test-health')

    agent = PlatformDriverAgent(driver_config_list=[], identity="platform.driver")

    # Create the server and connect the agent with the server
    ts = TestServer()
    ts.connect_agent(agent=agent)

    # The health.send_alert should send a pubsub message through the message bus
    agent.vip.health.send_alert("my_alert", Status.build(STATUS_BAD, "no context"))

Note that without ts = TestServer(); ts.connect_agent(agent=agent) will get error like the following

>       agent.vip.health.send_alert("my_alert", Status.build(STATUS_BAD, "no context"))

test_platform_driver_w_server.py:30: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../volttron-core/src/volttron/client/vip/agent/subsystems/health.py:80: in send_alert
    self._owner.vip.pubsub.publish("pubsub",
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <volttron.client.vip.agent.subsystems.pubsub.PubSub object at 0x7f0b917535e0>
peer = 'pubsub', topic = 'alerts/PlatformDriverAgent/None_platform_driver'
...
        args = ["publish", topic, dict(bus=bus, headers=headers, message=message)]
>       self.vip_socket.send_vip("", "pubsub", args, result.ident, copy=False)
E       AttributeError: 'NoneType' object has no attribute 'send_vip'

../../volttron-core/src/volttron/client/vip/agent/subsystems/pubsub.py:513: AttributeError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants