Skip to content

Commit

Permalink
testsuite: add a python test for service.add/remove
Browse files Browse the repository at this point in the history
Add python/t1000-service-add-remove.py to the testsuite to test
the connector-local usage of `service.add` and `service.remove`.
  • Loading branch information
grondo committed Oct 26, 2018
1 parent 5aa8663 commit 3a45f69
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
6 changes: 4 additions & 2 deletions t/Makefile.am
Expand Up @@ -120,7 +120,8 @@ TESTS = \
python/t0005-kvs.py \
python/t0006-request.py \
python/t0007-watchers.py \
python/t0008-jsc.py
python/t0008-jsc.py \
python/t1000-service-add-remove.py


if ENABLE_JOBSPEC
Expand Down Expand Up @@ -239,7 +240,8 @@ check_SCRIPTS = \
python/t0006-request.py \
python/t0007-watchers.py \
python/t0008-jsc.py \
python/t0009-security.py
python/t0009-security.py \
python/t1000-service-add-remove.py

check_PROGRAMS = \
shmem/backtoback.t \
Expand Down
91 changes: 91 additions & 0 deletions t/python/t1000-service-add-remove.py
@@ -0,0 +1,91 @@
#!/usr/bin/env python
import unittest
import errno
import flux.core as core
from flux.message import Message
from flux.core.inner import ffi
from flux.constants import ( FLUX_MSGTYPE_REQUEST,
FLUX_MSGTYPE_RESPONSE,
FLUX_NODEID_ANY )

from subflux import rerun_under_flux

def __flux_size():
return 2

def service_add (f, name):
future = f.flux_service_register (name)
return f.flux_future_get (future, ffi.NULL)

def service_remove (f, name):
future = f.flux_service_unregister (name)
return f.flux_future_get (future, ffi.NULL)


class TestServiceAddRemove(unittest.TestCase):
@classmethod
def setUpClass(self):
self.f = core.Flux()

@classmethod
def tearDownClass(self):
self.f.close()

def test_001_register_service (self):
rc = service_add (self.f, "foo")
self.assertEqual(rc, 0, msg="flux_service_register ('foo')")

def test_002_service_add_eexist (self):
with self.assertRaises(Exception) as e:
service_add (self.f, "foo")
self.assertEqual (e.exception.errno, errno.EEXIST)

def test_002_add_service_message_watcher (self):
def service_cb (f, t, msg, arg):
rc = f.respond (msg, 0, msg.payload_str)
self.assertEqual(rc, 0, msg="f.respond ()")
w1 = self.f.msg_watcher_create (service_cb,
FLUX_MSGTYPE_REQUEST,
"foo.echo")
self.assertIsNotNone(w1, msg="msg_watcher_create request handler")

def test_003_service_rpc (self):
p = { "test": "foo" }
def cb (f, t, msg, arg):
self.assertEqual (msg, p)
f.reactor_stop (f.get_reactor())

w2 = self.f.msg_watcher_create (cb, FLUX_MSGTYPE_RESPONSE,
"foo.echo")
self.assertIsNotNone(w2, msg="msg_watcher_create response handler")

m = Message()
m.topic = "foo.echo"
m.payload = p
self.assertTrue(m is not None)
ret = self.f.send (m)
self.assertEqual(ret, 0, msg="flux_send rc=0")

ret = self.f.reactor_run (self.f.get_reactor(), 0)
self.assertEqual (ret, 0, msg="Reactor exit with 0")

def test_004_unregister_service (self):
rc = service_remove (self.f, "foo")
self.assertEqual (rc, 0, msg="flux_service_register ('foo')")

def test_004_unregister_service_enoent (self):
with self.assertRaises(Exception) as e:
service_remove (self.f, "foo")
self.assertEqual (e.exception.errno, errno.ENOENT)

def test_005_service_rpc_enosys (self):
fut = self.f.flux_rpc ("foo.echo", "{}", FLUX_NODEID_ANY, 0)
with self.assertRaises(Exception) as e:
self.f.flux_future_get (fut, ffi.NULL)
self.assertEqual (e.exception.errno, errno.ENOSYS)


if __name__ == '__main__':
if rerun_under_flux(__flux_size()):
from pycotap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner(), verbosity=4)

0 comments on commit 3a45f69

Please sign in to comment.