def setUp(self): reload(config) reload(server) reload(utils) self.tmpdir = tempfile.mkdtemp(prefix="fetest-") with mock.patch('sys.argv', ['b******g', '--config_dir', self.tmpdir]): config.init() # Set ping rates REALLY low so these will move quickly config.set_value("ping_rate", .01) config.set_value("ping_max", .05) self.trigger = gevent.event.Event() self.server_loop_trigger = gevent.event.Event() def server_loop(): server.init() utils.spawn_gevent_func("main socket loop", "main", server.msg_loop) gevent.sleep() self.server_loop_trigger.wait() server.shutdown() self.server_greenlet = gevent.spawn(server_loop) # Start a new socket self.test_socket = HeartbeatTests.HeartbeatTestSocket(config.get_value("server_address"), self.trigger) # Attach to router self.test_socket_greenlet = gevent.spawn(self.test_socket.run)
def testConfigFileLoad(self): """load config files correctly""" config.set_value("server_address", "ipc://wat") reload(config) with mock.patch('sys.argv', ['b******g', '--config_dir', self.tmpdir]): config.init() self.failIf(config.get_value("server_address") != "ipc://wat")
def testInvalidConfigurationKeyLoad(self): """throw on screwed config files correctly""" config.set_value("server_address", "ipc://wat") # Insert bad key! with open(os.path.join(config._cdirs["config"], config.CONFIG_FILENAME), "w") as f: json.dump({"server_addres": "tcp://127.0.0.1:9389"}, f) reload(config) with mock.patch('sys.argv', ['b******g', '--config_dir', self.tmpdir]): try: config.init() self.fail("Didn't fail on gibberish json!") except KeyError: pass
def testInvalidConfigurationFileLoad(self): """throw on screwed config files correctly""" config.set_value("server_address", "ipc://wat") # Insert gibberish! with open(os.path.join(config._cdirs["config"], config.CONFIG_FILENAME), "w") as f: f.write("This is so not some f*****g json") reload(config) with mock.patch('sys.argv', ['b******g', '--config_dir', self.tmpdir]): try: config.init() self.fail("Didn't fail on gibberish json!") except ValueError: pass