Skip to content

isolate testing data between runs#1024

Closed
friedrichwilken wants to merge 2 commits intokyma-project:mainfrom
friedrichwilken:improve_int_test
Closed

isolate testing data between runs#1024
friedrichwilken wants to merge 2 commits intokyma-project:mainfrom
friedrichwilken:improve_int_test

Conversation

@friedrichwilken
Copy link
Contributor

Description

Changes proposed in this pull request:

  • reset testing data and state between individual tests

Related issue(s)

@github-actions
Copy link

Note(s) for PR Auther:

  • The integration test will be skipped for the PR. You can trigger it manually after adding the label: run-integration-test.
  • The evaluation test will be skipped for the PR. You can trigger it manually after adding the label: evaluation requested.
  • If any changes are made to the evaluation tests data, make sure that the integration tests are working as expected.
  • If any changes are made to how to run the unit tests, make sure to update the steps for unit-tests in the create-release.yml workflow as well.

Note(s) for PR Reviewer(s):

  • Make sure that the integration and evaluation tests are working as expected.

@friedrichwilken friedrichwilken deleted the improve_int_test branch February 24, 2026 12:04
@hyperspace-insights
Copy link
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Isolate Testing Data Between Runs

🧪 Test: Improved test isolation to prevent data leaks between test runs

This pull request addresses test isolation issues by ensuring that shared state and data are properly reset between individual test executions.

Changes

  • tests/integration/agents/test_followup_questions.py:

    • Added clear_shared_memory fixture with autouse=True to automatically clear shared memory before each test
    • Changed conversation_service fixture scope from session to function for proper isolation
  • tests/integration/conftest.py:

    • Changed start_fake_redis fixture scope from session to function to ensure fresh Redis instances per test
    • Changed companion_graph fixture scope from session to function to prevent state sharing across tests

These changes ensure that each test runs in a clean environment, preventing potential test failures caused by shared state or data contamination from previous test runs.

GitHub Issues

  • #123: fix: fix model name for GPT4o
  • #33: Follow-up questions during the conversation with companion
  • #43: Develop companion UI

  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.17.69 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback


💌 Have ideas or want to contribute? Create an issue and share your thoughts with us!
📑 Check out the documentation for more information.
📬 Subscribe to the Hyperspace PR Bot DL to get the latest announcements and pilot features!

Made with ❤️ by Hyperspace.

Copy link
Contributor

@hyperspace-insights hyperspace-insights bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

The pull request changes test fixture scopes to improve isolation, but introduces critical issues:

  1. Resource leaks: The start_fake_redis fixture creates a new server thread per test without guaranteed cleanup, potentially leaving orphaned threads.

  2. Incomplete cleanup: The clear_shared_memory fixture clears data before tests but not after, allowing data to leak between tests.

  3. Performance concerns: Moving from session to function scope significantly increases test execution time by recreating expensive Redis servers and graph instances for every test.

These issues should be addressed before merging to ensure the isolation goals are achieved without introducing new problems.

PR Bot Information

Version: 1.17.69 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • Correlation ID: 6e158300-1177-11f1-803b-200d8cced00f
  • LLM: anthropic--claude-4.5-sonnet
  • Event Trigger: pull_request.opened

Comment on lines +39 to +43
@pytest.fixture(autouse=True)
def clear_shared_memory():
"""Clear shared memory before each test to prevent data leaks."""
shared_memory.clear()
yield
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: clear_shared_memory fixture runs before conversation_service fixture but doesn't clear data inserted during test execution

The clear_shared_memory fixture with autouse=True clears shared_memory before each test, but line 126 writes shared_memory[given_conversation_id] = given_latest_state during test execution. This data persists until the next test's setup phase, potentially causing data leaks between tests if they execute in parallel or if cleanup fails.

The fixture should use yield with cleanup after the test completes, or the test should explicitly clear its entry.

Suggested change
@pytest.fixture(autouse=True)
def clear_shared_memory():
"""Clear shared memory before each test to prevent data leaks."""
shared_memory.clear()
yield
@pytest.fixture(autouse=True)
def clear_shared_memory():
"""Clear shared memory before each test to prevent data leaks."""
shared_memory.clear()
yield
shared_memory.clear()

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

Comment on lines +46 to 47
@pytest.fixture(scope="function")
def conversation_service(app_models, companion_graph):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic Error: Fixture scope changed from session to function but conversation_service depends on expensive fixtures that are still session-scoped

The conversation_service fixture (line 46) now has scope="function" but depends on app_models and companion_graph. The app_models fixture remains scope="session" (conftest.py line 80), while companion_graph was changed to scope="function". This creates an inconsistent dependency chain where conversation_service is recreated for each test function but some of its dependencies aren't, which may not achieve the isolation goal and creates unnecessary overhead recreating the service wrapper.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful



@pytest.fixture(scope="session")
@pytest.fixture(scope="function")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance: Changing fixture scope from session to function causes expensive Redis server and graph setup on every test function

The start_fake_redis and companion_graph fixtures now create new instances for each test function instead of once per session. This dramatically increases test execution time since each test will:

  1. Find a free port
  2. Start a new Redis server in a thread
  3. Initialize AsyncRedisSaver
  4. Create a new CompanionGraph with all models

For a test suite with dozens of tests using these fixtures, this could increase runtime from seconds to minutes. Consider using scope="module" or scope="class" as a middle ground if full session isolation isn't needed.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful



@pytest.fixture(scope="session")
@pytest.fixture(scope="function")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance: Creating CompanionGraph per function is expensive due to model initialization overhead

The companion_graph fixture depends on app_models (session-scoped) but now recreates the CompanionGraph for every test function. The CompanionGraph likely performs significant initialization work with the models. Since app_models is already session-scoped and shared, consider whether this fixture truly needs function scope or if module/class scope would suffice for isolation.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant