def Test_D_remove_polling(self): global default_mode if default_mode == watch_files.WF_POLLING: self.log.info( "Skipping remove test in polling mode, already tested as default" ) return snoop = watch_files.watch(polling=True, log=self.log, timeout=0.1, limit=3) self.log.info( "Default mode %s (%s), running remove test in polling mode", str(default_mode), snoop.get_mode_name(default_mode)) snoop.add(self.file_list) added_fds = len(support.find_open_fds()) assert len(self.file_list) > 1 snoop.remove(self.file_list[1]) remove_fds = len(support.find_open_fds()) if snoop.get_mode() == watch_files.WF_INOTIFYX: # inotify doesn't need open files for watches self.log.info("%d files open after remove, %d expected", remove_fds, added_fds) assert remove_fds == added_fds else: self.log.info("%d files open after remove, %d expected", remove_fds, added_fds - 1) assert remove_fds == added_fds - 1
def Test_C_remove(self): snoop = watch_files.watch(log=self.log, timeout=0.1, limit=3) snoop.add(self.file_list) added_fds = len(support.find_open_fds()) assert len(self.file_list) > 1 snoop.remove(self.file_list[1]) remove_fds = len(support.find_open_fds()) if snoop.get_mode() == watch_files.WF_INOTIFYX: # inotify doesn't need open files for watches self.log.info("%d files open after remove, %d expected", remove_fds, added_fds) assert remove_fds == added_fds else: self.log.info("%d files open after remove, %d expected", remove_fds, added_fds - 1) assert remove_fds == added_fds - 1
def setUpAll(self, mode=None): self.log = support.logger() self.log.info("%s started", self.__module__) self.start_fds = len(support.find_open_fds()) self.log.info("%d files open before watch started", self.start_fds) if not os.path.isdir(working_dir): os.mkdir(working_dir, 0x1FF) self.module_list = [] self.file_list = [] self.change_target = None prev_module = None for fname in reversed(test_modules): path = os.path.join(working_dir, fname + '.py') self.test_module = path with open(path, 'w') as f: if prev_module: f.write("import " + prev_module + "\n") prev_module = fname f.write(module_content) f.close() self.module_list.append(path) if self.change_target is None: self.change_target = path self.file_list.append(path) self.file_list.append(path + 'c') self.module_path = os.path.join(env.test_dir, self.__module__)
def Test_C_remove(self): snoop = watch_files.watch(log=self.log, timeout=0.1, limit=3) snoop.add(self.file_list) added_fds = len(support.find_open_fds()) assert len(self.file_list) > 1 snoop.remove(self.file_list[1]) remove_fds = len(support.find_open_fds()) if snoop.get_mode() == watch_files.WF_INOTIFYX: # inotify doesn't need open files for watches self.log.info("%d files open after remove, %d expected", remove_fds, added_fds) assert remove_fds == added_fds else: self.log.info("%d files open after remove, %d expected", remove_fds, added_fds - 1) assert remove_fds == added_fds - 1
def Test_A_add(self): global default_mode snoop = watch_files.watch(log=self.log, timeout=0.1, limit=3) default_mode = snoop.get_mode() self.log.info("Watching in %s mode", snoop.get_mode_name(default_mode)) snoop.add(self.file_list) open_fds = support.find_open_fds() self.log.info("%d files open watching %d paths with watch started", len(open_fds), len(snoop.paths_open)) self.log.debug("mapping after add: %s", support.known_fds(snoop, log=self.log))
def Test_D_remove_polling(self): global default_mode if default_mode == watch_files.WF_POLLING: self.log.info("Skipping remove test in polling mode, already tested as default") return snoop = watch_files.watch(polling=True, log=self.log, timeout=0.1, limit=3) self.log.info("Default mode %s (%s), running remove test in polling mode", str(default_mode), snoop.get_mode_name(default_mode)) snoop.add(self.file_list) added_fds = len(support.find_open_fds()) assert len(self.file_list) > 1 snoop.remove(self.file_list[1]) remove_fds = len(support.find_open_fds()) if snoop.get_mode() == watch_files.WF_INOTIFYX: # inotify doesn't need open files for watches self.log.info("%d files open after remove, %d expected", remove_fds, added_fds) assert remove_fds == added_fds else: self.log.info("%d files open after remove, %d expected", remove_fds, added_fds - 1) assert remove_fds == added_fds - 1
def Test_A_add(self): global default_mode snoop = watch_files.watch(log=self.log, timeout=0.1, limit=3) default_mode = snoop.get_mode() self.log.info("Watching in %s mode", snoop.get_mode_name(default_mode)) snoop.add(self.file_list) open_fds = support.find_open_fds() self.log.info("%d files open watching %d paths with watch started", len(open_fds), len(snoop.paths_open)) self.log.debug("mapping after add: %s", support.known_fds(snoop, log=self.log))
def setUpAll(self, mode=None): self.log = support.logger() self.log.info("%s started", self.__module__) self.start_fds = len(support.find_open_fds()) self.log.info("%d files open before watch started", self.start_fds) self.file_list = [] for fname in base_file_list: path = os.path.join(env.temp_dir, fname) with open(path, 'w') as f: f.write(path + '\n') self.file_list.append(path)
def setUpAll(self, mode=None): self.log = support.logger() self.log.info("%s started", self.__module__) self.start_fds = len(support.find_open_fds()) self.log.info("%d files open before watch started", self.start_fds) self.file_list = [] for fname in base_file_list: path = os.path.join(env.temp_dir, fname) with open(path, 'w') as f: f.write(path + '\n') self.file_list.append(path)
def Test_F_watch(self): snoop = watch_files.watch(log=self.log, timeout=0.1, limit=3) snoop.add(self.file_list) self.log.info("%d files open watching %d paths with watch started", len(support.find_open_fds()), len(snoop.paths_open)) touched = False pset = poll.poll() pset.register(snoop, poll.POLLIN) while True: try: evlist = pset.poll(1000) except OSError as e: self.log.info("poll() exception -- %s", str(e)) if e.errno != errno.EINTR: raise e if not evlist: self.log.info("poll() timeout, will touch") snoop.scan() with open(self.file_list[0], 'w') as f: f.write(self.file_list[0] + '\n') touched = True continue if not touched: self.log.info("Premature change detected") for path in snoop.get(): self.log.info(' %s', path) continue self.log.info('Change detected') assert touched for path in snoop.get(): self.log.info(' %s', path) assert path == self.file_list[0] break del_fds = support.find_open_fds() self.log.info("%d files open after watch: %s", len(del_fds), str(del_fds)) self.log.debug("paths known to watcher: %s", support.known_fds(snoop, log=self.log))
def setUpAll(self): self.log = support.logger() self.log.info("%s started", self.__module__) self.start_fds = len(support.find_open_fds()) self.startenv = {} self.delenv = [] for tag in ['PATH', 'PYTHONPATH', 'EXAMPLES_BASE']: if tag in os.environ: self.startenv[tag] = os.environ[tag] else: self.delenv.append(tag) self.log.info("%d files open before task testing", self.start_fds) self.file_list = [env.roles_file]
def Test_F_watch(self): snoop = watch_files.watch(log=self.log, timeout=0.1, limit=3) snoop.add(self.file_list) self.log.info("%d files open watching %d paths with watch started", len(support.find_open_fds()), len(snoop.paths_open)) touched = False pset = poll.poll() pset.register(snoop, poll.POLLIN) while True: try: evlist = pset.poll(1000) except OSError as e: self.log.info("poll() exception -- %s", str(e)) if e.errno != errno.EINTR: raise e if not evlist: self.log.info("poll() timeout, will touch") snoop.scan() with open(self.file_list[0], 'w') as f: f.write(self.file_list[0] + '\n') touched = True continue if not touched: self.log.info("Premature change detected") for path in snoop.get(): self.log.info(' %s', path) continue self.log.info('Change detected') assert touched for path in snoop.get(): self.log.info(' %s', path) assert path == self.file_list[0] break del_fds = support.find_open_fds() self.log.info("%d files open after watch: %s", len(del_fds), str(del_fds)) self.log.debug("paths known to watcher: %s", support.known_fds(snoop, log=self.log))
def Test_C_watch(self): snoop = watch_modules.watch(log=self.log, module_path=working_dir) snoop.add(self.test_module) self.log.info("Watch setup: %d module%s for %d command%s", len(snoop.modules), '' if len(snoop.modules) == 1 else 's', len(snoop.names), '' if len(snoop.names) == 1 else 's') touched = False pset = poll.poll() pset.register(snoop, poll.POLLIN) while True: try: evlist = pset.poll(1000) except OSError as e: self.log.info("poll() exception -- %s", str(e)) if e.errno != errno.EINTR: raise e if not evlist: self.log.info("poll() timeout, will touch") snoop.scan() with open(self.change_target, 'w') as f: f.write(module_content) touched = True continue if not touched: self.log.info("Premature change detected") for path in snoop.get(): self.log.info(' %s', path) continue self.log.info('Change detected') assert touched for name, path, module_list in snoop.get(timeout=0): self.log.info(' %s', path) assert path == os.path.realpath(self.test_module) break del pset del_fds = support.find_open_fds() self.log.info("%d files open after watch: %s", len(del_fds), str(del_fds)) self.log.info("paths known to watcher: %s", support.known_fds(snoop._watch, log=self.log))
def Test_G_cleanup_test(self): del_fds = len(support.find_open_fds()) self.log.info("%d files open after object delete, %d expected", del_fds, self.start_fds) assert del_fds == self.start_fds
def Test_B_autodel(self): del_fds = len(support.find_open_fds()) self.log.info("%d files open after auto object delete", del_fds) assert del_fds == self.start_fds
def Test_D_autodel(self): del_fds = len(support.find_open_fds()) self.log.info("%d files open after auto object delete", del_fds) assert del_fds == self.start_fds
def Test_G_cleanup_test(self): del_fds = len(support.find_open_fds()) self.log.info("%d files open after object delete, %d expected", del_fds, self.start_fds) assert del_fds == self.start_fds