Skip to content

Commit

Permalink
Merge pull request #21 from craig8/feature/v11-test-updates
Browse files Browse the repository at this point in the history
Feature/v11 test updates
  • Loading branch information
schandrika authored Oct 25, 2024
2 parents 5dd1ea9 + 241f649 commit f360442
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 16 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/auto-assign-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Add bugs to bugs project

on:
issues:
types:
- opened

jobs:
add-to-project:
name: Add issue to project
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
# You can target a repository in a different organization
# to the issue
project-url: https://github.com/orgs/eclipse-volttron/projects/3
# project-url: https://github.com/orgs/<orgName>/projects/<projectNumber>
# github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
github-token: ${{ secrets.AUTO_PROJECT_PAT }}
# labeled: bug, needs-triage
# label-operator: OR
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
![Passing?](https://github.com/eclipse-volttron/volttron-listener/actions/workflows/run-tests.yml/badge.svg)
[![pypi version](https://img.shields.io/pypi/v/volttron.svg)](https://pypi.org/project/volttron/)
[![pypi version](https://img.shields.io/pypi/v/volttron-listener.svg)](https://pypi.org/project/volttron-listener/)

The volttron-listener agent prints all message traffic across a VOLTTRON bus to standard out.

Expand Down
18 changes: 16 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "volttron-listener"
version = "2.0.0rc1"
version = "2.0.0rc2"
description = "The volttron-listener agent allows publishing of message bus traffic to standard out."
authors = [
"VOLTTRON Team <[email protected]>",
Expand All @@ -24,11 +24,25 @@ classifiers = [

[tool.poetry.dependencies]
python = ">=3.10,<4.0"
volttron-core = ">=2.0.0rc0"
volttron-core = {path="../volttron-core", develop = true}

[tool.poetry.group.dev]
optional = true

[tool.poetry.group.dev.dependencies]
volttron-testing = {path = "../volttron-testing", develop = true}
volttron-lib-zmq = {path = "../volttron-lib-zmq", develop = true}
volttron-lib-auth = {path = "../volttron-lib-auth", develop = true}

# These will either be brought in elsewhere if you have a multi-project environment or uncomment locally to work
# against a specific path.
#volttron-lib-zmq = {path = "../volttron-lib-zmq", develop = true}
#volttron-lib-auth = {path = "../volttron-lib-auth", develop = true}

[tool.poetry.scripts]
volttron-listener-agent = "listener.agent:main"


[tool.yapfignore]
ignore_patterns = [
".venv/**",
Expand Down
2 changes: 1 addition & 1 deletion src/listener/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from pprint import pformat
import datetime

from volttron.client.vip.agent.subsystems.configstore import VALID_ACTIONS
from volttron.utils.commands import vip_main
from volttron.client.messaging.health import STATUS_GOOD
from volttron.client.vip.agent import Agent, Core, PubSub
Expand Down Expand Up @@ -81,7 +82,6 @@ def onsetup(self, sender, **kwargs):
@Core.receiver('onstart')
def onstart(self, sender, **kwargs):
# TODO: Bring back version?
pass
#_log.debug("VERSION IS: {}".format(self.core.version()))
if self._heartbeat_period != 0:
_log.debug(f"Heartbeat starting for {self.core.identity} published every {self._heartbeat_period}")
Expand Down
5 changes: 4 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@
if path.resolve() not in sys.path:
sys.path.insert(0, path.resolve().as_posix())

from volttrontesting.fixtures.volttron_platform_fixtures import *
from volttrontesting.fixtures import get_pyproject_toml
from volttrontesting.fixtures.volttron_platform_fixtures import volttron_instance


18 changes: 15 additions & 3 deletions tests/test_agent_workings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,29 @@

import logging
from pathlib import Path
import os

from volttron.types.agent_context import AgentOptions

from listener.agent import ListenerAgent, _log

from volttrontesting import TestServer
import shutil


def test_agent():
def test_agent(monkeypatch):
with open("/tmp/cfg.json", 'w') as fp:
fp.write("{}")

try:
la = ListenerAgent(config_path="/tmp/cfg.json")
os.environ['AGENT_VIP_IDENTITY'] = 'brown.cow'
ts = TestServer()

la: ListenerAgent = ts.instantiate_agent(ListenerAgent, config_path="/tmp/cfg.json")

assert la.core

# la = ListenerAgent(config_path="/tmp/cfg.json")
ts.connect_agent(agent=la, logger=_log)
assert ts
resp = ts.trigger_setup_event(identity_or_agent=la)
Expand All @@ -47,6 +57,7 @@ def test_agent():
assert resp.response is None
assert resp.called_method == 'onstart'


ts.publish("atestmessage", message="Woot we got this")
assert len(ts.get_published_messages()) == 1

Expand All @@ -59,6 +70,7 @@ def test_agent():
assert len(ts.get_server_log()) > 1

finally:
shutil.rmtree(TestServer.__volttron_home__)
Path("/tmp/cfg.json").unlink(missing_ok=True)


Expand All @@ -67,8 +79,8 @@ def test_agent_pubsub():
with open("/tmp/cfg.json", 'w') as fp:
fp.write("{}")

la = ListenerAgent(config_path="/tmp/cfg.json")
ts = TestServer()
la = ts.instantiate_agent(ListenerAgent, config_path="/tmp/cfg.json")
ts.connect_agent(agent=la, logger=_log)
assert ts
resp = ts.trigger_setup_event(la)
Expand Down
19 changes: 11 additions & 8 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
from unittest.mock import MagicMock

import gevent
from cattrs.fns import identity
from volttrontesting import PlatformWrapper
from volttron.client.known_identities import CONTROL

from volttrontesting.platformwrapper import InstallAgentOptions


def test_startup_instance(volttron_instance: PlatformWrapper):
assert volttron_instance.is_running()
Expand All @@ -42,15 +45,14 @@ def test_startup_instance(volttron_instance: PlatformWrapper):
assert vi.is_running()

# agent identity should be
auuid = vi.install_agent(agent_dir=agent_pth,
start=False)
auuid = vi.install_agent(agent_dir=agent_pth, install_options=InstallAgentOptions(start=False))
assert auuid is not None
time.sleep(1)
started = vi.start_agent(auuid)

assert started
assert vi.is_agent_running(auuid)
listening = vi.build_agent()
listening = vi.build_agent(identity="world")
listening.callback = MagicMock(name="callback")
listening.callback.reset_mock()

Expand All @@ -76,8 +78,9 @@ def test_startup_instance(volttron_instance: PlatformWrapper):
assert 'TimeStamp' in call_args[4]
assert 'GOOD' in call_args[5]

stopped = vi.stop_agent(auuid)
print('STOPPED: ', stopped)
removed = vi.remove_agent(auuid)
print('REMOVED: ', removed)
listening.core.stop()
# TODO: Setup test in platform testing to deal with the stop issue.
# stopped = vi.stop_agent(auuid)
# print('STOPPED: ', stopped)
# removed = vi.remove_agent(auuid)
# print('REMOVED: ', removed)
# listening.core.stop()

0 comments on commit f360442

Please sign in to comment.