Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix File Handling to Prevent Crashes and Errors #1000

Closed
wants to merge 11 commits into from

Conversation

TeachMeTW
Copy link
Contributor

Summary

This PR resolves an issue where improper file handling caused terminal crashes and the following error:
ValueError: I/O operation on closed file
when running runAllTests.sh

The error occurred because the code attempted to read from a file after it had already been closed. The issue was present both in the original code, which didn’t explicitly close the file, and in a later version where a redundant file read was placed after the file had been closed by a with statement.

Changes Made

  • Updated file handling to use with statements for proper resource management and automatic file closing.
  • Removed redundant query_string = "".join(query_file.readlines()) line that attempted to read the file after it had been closed.
  • Ensured query_string is fully assigned within the scope of the with block.

Impact

  • Fixes ValueError: I/O operation on closed file.
  • Prevents terminal crashes during script execution.

How to Test

  1. Run the script that previously caused the terminal to crash.
  2. Verify that there are no ValueError exceptions in the logs.

Affected #993

Addressed comments, reduced overkill on refactor

Forgot to add last_call_ts
- Introduced comprehensive test suite to validate functionality of the `get_and_store_user_stats` method.
- Covered core scenarios including:
  - Correct data aggregation and storage.
  - Handling cases with no trips or missing data.
  - Verifying behavior with partial data and multiple invocations.
  - handling of invalid UUID inputs.
- setup and teardown to ensure test isolation and clean up user data.
- Included data insertion for confirmed trips, composite trips, and server API timestamps to simulate realistic scenarios.

This initial test suite establishes a baseline for ensuring reliability of the `get_and_store_user_stats` function.

remove

Modified test

Refactored the test and simplified it; validated all new user stats
- Replaced manual file open/close with `with` statement to ensure proper resource management.
- Removed redundant file read operation after the file was closed.
- Resolved `ValueError: I/O operation on closed file` and addressed terminal crashing issue during execution.
@TeachMeTW TeachMeTW closed this Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant