def replay(xom, replica_xom, events=True): if replica_xom.replica_thread.replica_in_sync_at is None: # allow on_import to run right away, so we don't need to rely # on the initial import thread for tests replica_xom.replica_thread.replica_in_sync_at = 0 threadlog.info("test: replaying replica") for serial in range(replica_xom.keyfs.get_next_serial(), xom.keyfs.get_next_serial()): if serial == -1: continue with xom.keyfs._storage.get_connection() as conn: change_entry = conn.get_changes(serial) threadlog.info("test: importing to replica %s", serial) replica_xom.keyfs.import_changes(serial, change_entry) # replay notifications if events: replica_xom.replica_thread.wait() noti_thread = replica_xom.keyfs.notifier event_serial = noti_thread.read_event_serial() thread_push_log("NOTI") while event_serial < replica_xom.keyfs.get_current_serial(): event_serial += 1 noti_thread._execute_hooks(event_serial, threadlog, raising=True) noti_thread.write_event_serial(event_serial) thread_pop_log("NOTI")
def thread_run(self): thread_push_log("[IDXQ]") with self.xom.keyfs.transaction(write=False) as tx: indexer = get_indexer(self.xom) searcher = indexer.get_project_ix().searcher() self.shared_data.queue_projects(iter_projects(self.xom), tx.at_serial, searcher)
def test_taglogger_push(caplog): log = thread_push_log("hello") log.info("42") assert caplog.records[0].msg == "hello 42" log = thread_push_log("world") log.info("17") assert caplog.records[1].msg == "hello world 17" thread_pop_log() log = thread_current_log() log.info("10") assert caplog.records[2].msg == "hello 10"
def replay(xom, replica_xom, events=True): threadlog.info("test: replaying replica") for serial in range(replica_xom.keyfs.get_next_serial(), xom.keyfs.get_next_serial()): if serial == -1: continue with xom.keyfs._storage.get_connection() as conn: change_entry = conn.get_changes(serial) threadlog.info("test: importing to replica %s", serial) replica_xom.keyfs.import_changes(serial, change_entry) # replay notifications if events: noti_thread = replica_xom.keyfs.notifier event_serial = noti_thread.read_event_serial() thread_push_log("NOTI") while event_serial < replica_xom.keyfs.get_current_serial(): event_serial += 1 noti_thread._execute_hooks(event_serial, threadlog, raising=True) noti_thread.write_event_serial(event_serial) thread_pop_log("NOTI")
def thread_run(self): thread_push_log("[IDX]") last_time = time.time() event_serial = None serial = -1 while 1: try: if time.time() - last_time > 5: last_time = time.time() size = self.shared_data.queue.qsize() if size: log.info("Indexer queue size ~ %s" % size) event_serial = self.xom.keyfs.notifier.read_event_serial() serial = self.xom.keyfs.get_current_serial() if event_serial is not None and event_serial < serial: # be nice to everything else self.thread.sleep(1.0) self.tick() except mythread.Shutdown: raise except Exception: log.exception("Unhandled exception in indexer thread.") self.thread.sleep(1.0)
def __enter__(self): self.log = thread_push_log("fswriter%s:" % self.storage.next_serial) return self
def test_threadlog(caplog): threadlog.info("hello") assert caplog.records[0].msg == "NOCTX hello" thread_push_log("this") threadlog.info("hello") assert caplog.records[1].msg == "this hello"
def test_taglogger_wrong_prefix(caplog): thread_push_log("hello") with pytest.raises(ValueError): thread_pop_log("this")