def testComplete(self) -> None: et = EventTracer() et.complete(nanotime(), 1000000, "complete item") self.assertEqual(1, len(et.buffer)) self.assertArraySubset({ "ph": "X", "name": "complete item" }, et.buffer[0])
def testFlushingWrites(self) -> None: # Write two streams and make sure there's only one beginning et1 = EventTracer() et2 = EventTracer() et1.complete(nanotime(), 1, "flushed 1") et2.complete(nanotime(), 1, "flushed 2") et1.flush(self.tmpfile) et2.flush(self.tmpfile) # finished_data = data, minus trailing comma, plus closing brace with open(self.tmpfile) as fp: data = fp.read() finished_data = data[:-2] + "\n]" buffer = json.loads(finished_data) self.assertEqual(2, len(buffer))
def testStreamingWrites(self) -> None: # Write two streams and make sure there's only one beginning et1 = EventTracer(self.tmpfile) et2 = EventTracer(self.tmpfile) et1.complete(nanotime(), 1, "item 1") et2.complete(nanotime(), 1, "item 2") # finished_data = data, minus trailing comma, plus closing brace with open(self.tmpfile) as fp: data = fp.read() finished_data = data[:-2] + "\n]" try: buffer = json.loads(finished_data) self.assertEqual(2, len(buffer)) except Exception: print(finished_data) raise
def greet(et: EventTracer, name: str) -> None: global out et.complete(nanotime(), 200000, f"greeting {name}") out += f"{name}\n" sleep(2)