Skip to content

Commit

Permalink
Notify subscribers of counter value updates
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Jun 23, 2016
1 parent aced1f4 commit 7cfca48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion malcolm/controllers/countercontroller.py
@@ -1,7 +1,7 @@
from malcolm.core.controller import Controller
from malcolm.core.attribute import Attribute
from malcolm.core.numbermeta import NumberMeta
from malcolm.core.method import takes, returns
from malcolm.core.method import takes

import numpy as np

Expand All @@ -16,7 +16,9 @@ def create_attributes(self):
@takes()
def reset(self):
self.counter.set_value(0)
self.block.notify_subscribers()

@takes()
def increment(self):
self.counter.set_value(self.counter.value + 1)
self.block.notify_subscribers()
6 changes: 5 additions & 1 deletion tests/test_core/test_system_core.py
Expand Up @@ -56,7 +56,8 @@ def test_counter_controller_subscribe(self):
q = sync_factory.create_queue()

sub = Request.Subscribe(response_queue=q, context="ClientConnection",
endpoint=["counting", "counter"], delta=False)
endpoint=["counting", "counter"],
delta=False)
process.q.put(sub)
resp = q.get(timeout=1)
self.assertEqual(Response.UPDATE, resp.type_)
Expand All @@ -67,6 +68,9 @@ def test_counter_controller_subscribe(self):
endpoint=["counting", "increment"])
process.q.put(post)
resp = q.get(timeout=1)
self.assertEqual(Response.UPDATE, resp.type_)
self.assertEqual(resp.value["value"], 1)
resp = q.get(timeout=1)
self.assertEqual(Response.RETURN, resp.type_)


Expand Down

0 comments on commit 7cfca48

Please sign in to comment.