Skip to content

Commit

Permalink
Fixing errors in test. (#287)
Browse files Browse the repository at this point in the history
* appease call service using timeout and proper arrival waiting

* add queue_size on publisher

* test them individually.

* add time after wait for service
  • Loading branch information
jihoonl authored Aug 30, 2017
1 parent f8d8a4d commit b8c85ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion rosbridge_library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ catkin_package(
# Test launch files
if (CATKIN_ENABLE_TESTING)
find_package(rostest REQUIRED)
add_rostest(test/test_all.test)
add_rostest(test/capabilities/test_capabilities.test)
add_rostest(test/internal/test_internal.test)
endif()
25 changes: 18 additions & 7 deletions rosbridge_library/test/capabilities/test_call_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,29 @@ def test_call_service_works(self):
# First, call the service the 'proper' way
p = rospy.ServiceProxy("/rosout/get_loggers", GetLoggers)
p.wait_for_service()
time.sleep(1.0)
ret = p()


proto = Protocol("test_call_service_works")
s = CallService(proto)
msg = loads(dumps({"op": "call_service", "service": "/rosout/get_loggers"}))

received = {"msg": None}
received = {"msg": None, "arrived": False}

def cb(msg, cid=None):
received["msg"] = msg
received["arrived"] = True

proto.send = cb

s.call_service(msg)

time.sleep(0.5)
timeout = 5.0
start = rospy.Time.now()
while rospy.Time.now() - start < rospy.Duration(timeout):
if received["arrived"]:
break
time.sleep(0.1)

self.assertTrue(received["msg"]["result"])
for x, y in zip(ret.loggers, received["msg"]["values"]["loggers"]):
Expand All @@ -65,16 +71,21 @@ def test_call_service_fail(self):
s = CallService(proto)
send_msg = loads(dumps({"op": "call_service", "service": "/rosout/set_logger_level", "args": '["ros", "invalid"]'}))

received = {"msg": None}

def cb(msg, cid=None):
received = {"msg": None, "arrived": False}
def cb(msg, cid=None):
received["msg"] = msg
received["arrived"] = True

proto.send = cb

s.call_service(send_msg)

time.sleep(0.5)
timeout = 5.0
start = rospy.Time.now()
while rospy.Time.now() - start < rospy.Duration(timeout):
if received["arrived"]:
break
time.sleep(0.1)

self.assertFalse(received["msg"]["result"])

Expand Down
2 changes: 1 addition & 1 deletion rosbridge_library/test/capabilities/test_subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def send(outgoing):

sub.subscribe(loads(dumps({"op": "subscribe", "topic": topic, "type": msg_type})))

p = rospy.Publisher(topic, String)
p = rospy.Publisher(topic, String, queue_size=5)
time.sleep(0.25)
p.publish(msg)

Expand Down

0 comments on commit b8c85ac

Please sign in to comment.