def test_writing_and_reading_from_file(temp_dir): activity_log = ActivityLog(temp_dir) print(f"Using: {temp_dir}") event1 = Event.new_push_to_inverter("testInvId", "testUserId") yield ensureDeferred(activity_log.add(event1)) activity_log = ActivityLog(temp_dir) assert activity_log.has_cached_events() is False activity_log._read_cache_file() event2 = activity_log.read_oldest_event() assert event1.inverter_id == event2.inverter_id
def test_benchmark_mass_writes(temp_dir): activity_log = ActivityLog(temp_dir) print(f"Using: {temp_dir}") start = time.time() for _ in range(1000): event = Event.new_push_to_inverter("testInvId", "testUserId") yield ensureDeferred(activity_log.add(event)) elapsed = time.time() - start print(f"Writing 1000 events took {elapsed:.2f}") time.sleep(1) start = time.time() event = Event.new_push_to_inverter("testInvId", "testUserId") yield ensureDeferred(activity_log.add(event)) elapsed = time.time() - start print(f"Writing last event took {elapsed:.2f}") activity_log = ActivityLog(temp_dir) start = time.time() activity_log._read_cache_file() elapsed = time.time() - start print(f"Reading 1001 events took {elapsed:.2f}")