Esempio n. 1
0
    def Test_C_poll(self):
        log_level = self.log.getEffectiveLevel()

        poll_fd, poll_send = self.self_pipe()

        poll = taskforce.poll.poll()
        poll.register(poll_fd, taskforce.poll.POLLIN)

        #  Check active poll
        os.write(poll_send, '\0'.encode('utf-8'))
        evlist = poll.poll(timeout=30)
        self.dump_evlist(poll, 'active poll', evlist)
        assert evlist
        assert len(os.read(poll_fd, 10)) == 1

        #  Check timeout
        evlist = poll.poll(timeout=30)
        self.dump_evlist(poll, 'timeout poll', evlist)
        assert evlist == []

        #  Check timeout accuracy
        start = time.time()
        delay = 500
        evlist = poll.poll(timeout=500)
        self.dump_evlist(poll, 'timeout accuracy', evlist)
        assert evlist == []
        delta = abs(time.time() - start - delay/1000.0)
        self.log.info("%s poll timeout delta from wall clock %s", my(self), deltafmt(delta, decimals=6))
        assert delta < 0.1

        if poll.get_mode() == taskforce.poll.PL_SELECT:
            self.log.warning("%s Default mode is PL_SELECT so retest skipped", my(self))
        else:
            poll = taskforce.poll.poll()
            poll.set_mode(taskforce.poll.PL_SELECT)
            poll.register(poll_fd, taskforce.poll.POLLIN)

            #  Check active poll
            os.write(poll_send, '\0'.encode('utf-8'))
            evlist = poll.poll(timeout=30)
            self.dump_evlist(poll, 'select active poll', evlist)
            assert evlist
            assert len(os.read(poll_fd, 10)) == 1

            #  Check timeout
            evlist = poll.poll(timeout=30)
            self.dump_evlist(poll, 'select timeout poll', evlist)
            assert evlist == []

            #  Check timeout accuracy
            start = time.time()
            delay = 500
            evlist = poll.poll(timeout=500)
            self.dump_evlist(poll, 'select timeout accuracy', evlist)
            assert evlist == []
            delta = abs(time.time() - start - delay/1000.0)
            self.log.info("%s select poll timeout delta from wall clock %s", my(self), deltafmt(delta, decimals=6))
            assert delta < 0.1

        self.close_pipe()
Esempio n. 2
0
	def Test_C_poll(self):
		log_level = self.log.getEffectiveLevel()

		poll_fd, poll_send = self.self_pipe()

		poll = taskforce.poll.poll()
		poll.register(poll_fd, taskforce.poll.POLLIN)

		#  Check active poll
		os.write(poll_send, '\0'.encode('utf-8'))
		evlist = poll.poll(timeout=30)
		self.dump_evlist(poll, 'active poll', evlist)
		assert evlist
		assert len(os.read(poll_fd, 10)) == 1

		#  Check timeout
		evlist = poll.poll(timeout=30)
		self.dump_evlist(poll, 'timeout poll', evlist)
		assert evlist == []

		#  Check timeout accuracy
		start = time.time()
		delay = 500
		evlist = poll.poll(timeout=500)
		self.dump_evlist(poll, 'timeout accuracy', evlist)
		assert evlist == []
		delta = abs(time.time() - start - delay/1000.0)
		self.log.info("%s poll timeout delta from wall clock %s", my(self), deltafmt(delta, decimals=6))
		assert delta < 0.1

		if poll.get_mode() == taskforce.poll.PL_SELECT:
			self.log.warning("%s Default mode is PL_SELECT so retest skipped", my(self))
		else:
			poll = taskforce.poll.poll()
			poll.set_mode(taskforce.poll.PL_SELECT)
			poll.register(poll_fd, taskforce.poll.POLLIN)

			#  Check active poll
			os.write(poll_send, '\0'.encode('utf-8'))
			evlist = poll.poll(timeout=30)
			self.dump_evlist(poll, 'select active poll', evlist)
			assert evlist
			assert len(os.read(poll_fd, 10)) == 1

			#  Check timeout
			evlist = poll.poll(timeout=30)
			self.dump_evlist(poll, 'select timeout poll', evlist)
			assert evlist == []

			#  Check timeout accuracy
			start = time.time()
			delay = 500
			evlist = poll.poll(timeout=500)
			self.dump_evlist(poll, 'select timeout accuracy', evlist)
			assert evlist == []
			delta = abs(time.time() - start - delay/1000.0)
			self.log.info("%s select poll timeout delta from wall clock %s", my(self), deltafmt(delta, decimals=6))
			assert delta < 0.1

		self.close_pipe()
Esempio n. 3
0
 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))
Esempio n. 4
0
 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))
Esempio n. 5
0
 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))