def setup_test_suite(): """General test suite setup (handles cacheserver and elog server)""" # make the test suite run the same independent of the hostname os.environ['INSTRUMENT'] = 'test' try: cleanup() except OSError: sys.stderr.write('Failed to clean up old test dir. Check if NICOS ' 'processes are still running.') sys.stderr.write('=' * 80) raise cache = startCache(cache_addr) elog = startSubprocess('elog') yield killSubprocess(elog) killSubprocess(cache)
def test_basic(session, setup): cache = startCache(alt_cache_addr, setup) try: sleep(1) cc = session.cache testval = 'test1' key = 'value' cc.put('testcache', key, testval, ttl=10) cc.flush() cachedval_local = cc.get('testcache', key, None) cachedval = cc.get_explicit('testcache', key, None) cachedval2 = cc.get_explicit('testcache', key, None) print(cachedval_local, cachedval, cachedval2) assert cachedval_local == testval assert cachedval[2] == testval assert cachedval2[2] == testval finally: killSubprocess(cache)
def test_restart(session, setup): cc = session.cache testval = 'test2' key = 'value' cc.put('testcache', key, testval) cachedval_local = cc.get('testcache', key, None) assert raises(CacheError, cc.get_explicit, 'testcache', key, None) sleep(1) cache = startCache(alt_cache_addr, setup) try: sleep(1) cc.flush() cachedval2 = cc.get_explicit('testcache', key, None) print(cachedval2) assert cachedval_local == testval assert cachedval2[2] == testval finally: killSubprocess(cache)
def console(): """Run a nicos console (aka AIO)""" console = startSubprocess('aio', piped=True) yield console killSubprocess(console)
def daemon(): """Start a nicos daemon""" daemon = startSubprocess('daemon', wait_cb=daemon_wait_cb) yield killSubprocess(daemon)