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

Development: Fix exercise deletion with existing Iris sessions #9567

Merged
merged 5 commits into from
Oct 24, 2024

Conversation

MichaelOwenDyer
Copy link
Contributor

@MichaelOwenDyer MichaelOwenDyer commented Oct 23, 2024

Checklist

General

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) and too complex database calls.
  • I strictly followed the principle of data economy for all database calls.
  • I strictly followed the server coding and design guidelines.
  • I added multiple integration tests (Spring) related to the features (with a high test coverage).
  • I added pre-authorization annotations according to the guidelines and checked the course groups for all new REST Calls (security).
  • I documented the Java code using JavaDoc style.

Motivation and Context

Currently, we are unable to delete exercises which have any associated iris sessions in the database, due to a foreign key integrity violation. This PR adds a database migration to introduce a cascading delete on that foreign key, so when an exercise is deleted, all associated sessions are automatically deleted as well. This also triggers (already existing) cascading deletes of all of the session's messages, and all of those messages' contents.

As far as I know, there are no foreign keys referencing iris_session anywhere else in the database, so this change should not introduce further integrity issues.

Description

  • Added a liquibase changeset which drops the existing foreign key constraint and re-adds it with a cascading delete.
  • Added an integration test to catch this issue in the future

Steps for Testing

Prerequisites:

  • Artemis with Iris globally enabled
  • 1 Course with Iris enabled
  • 1 Exercise (either Programming or Text, as those are the ones where Iris is supported)
  1. Start a chat with Iris in the exercise
  2. Try to delete the exercise

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Performance Review

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Summary by CodeRabbit

  • Tests
    • Introduced a new test to verify the deletion of a programming exercise and its associated Iris session, enhancing integration test coverage.

@MichaelOwenDyer MichaelOwenDyer requested a review from a team as a code owner October 23, 2024 13:32
@github-actions github-actions bot added tests database Pull requests that update the database. (Added Automatically!). Require a CRITICAL deployment. iris Pull requests that affect the corresponding module labels Oct 23, 2024
Copy link

coderabbitai bot commented Oct 23, 2024

Walkthrough

The pull request introduces a new test method testDeleteExerciseWithIrisSession in the IrisExerciseChatSessionIntegrationTest class. This method verifies that when a programming exercise is deleted, the associated Iris session is also removed. The test creates an Iris session, confirms its existence, deletes the programming exercise, and checks that the Iris session no longer exists in the repository. Additionally, the initTestCase method has been modified to change the number of users added from 0 to 1.

Changes

File Path Change Summary
src/test/java/de/tum/cit/aet/artemis/iris/IrisExerciseChatSessionIntegrationTest.java Added method void testDeleteExerciseWithIrisSession() to test deletion of exercise and associated Iris session. Modified initTestCase to change user count from 0 to 1.

Suggested labels

bugfix, server, ready for review, core

Suggested reviewers

  • ole-ve
  • dfuchss
  • JohannesStoehr
  • krusche

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
src/test/java/de/tum/cit/aet/artemis/iris/IrisExerciseChatSessionIntegrationTest.java (1)

93-93: Consider adding test for multiple Iris sessions.

To ensure comprehensive testing of the cascade delete functionality, consider adding a test case that verifies deletion of multiple Iris sessions associated with the same exercise.

Here's a suggested test case:

@Test
@WithMockUser(username = TEST_PREFIX + "student1", roles = "USER")
void testDeleteExerciseWithMultipleIrisSessions() throws Exception {
    // Given
    database.resetTrackedQueries();
    var irisSession1 = request.postWithResponseBody(exerciseChatUrl(exercise.getId()), null, IrisSession.class, HttpStatus.CREATED);
    var irisSession2 = request.postWithResponseBody(exerciseChatUrl(exercise.getId()), null, IrisSession.class, HttpStatus.CREATED);
    
    assertThat(irisExerciseChatSessionRepository.findAllById(List.of(irisSession1.getId(), irisSession2.getId())))
        .as("Both Iris sessions should exist before exercise deletion")
        .hasSize(2);

    // When
    request.delete("/api/programming-exercises/" + exercise.getId(), HttpStatus.OK);

    // Then
    assertThat(irisExerciseChatSessionRepository.findAllById(List.of(irisSession1.getId(), irisSession2.getId())))
        .as("All Iris sessions should be deleted along with the exercise")
        .isEmpty();
    database.assertMaxQueryCount(7); // Adjust the number based on expected queries
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c17b2c4 and d8b526c.

⛔ Files ignored due to path filters (2)
  • src/main/resources/config/liquibase/changelog/20241023456789_changelog.xml is excluded by !**/*.xml
  • src/main/resources/config/liquibase/master.xml is excluded by !**/*.xml
📒 Files selected for processing (1)
  • src/test/java/de/tum/cit/aet/artemis/iris/IrisExerciseChatSessionIntegrationTest.java (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/test/java/de/tum/cit/aet/artemis/iris/IrisExerciseChatSessionIntegrationTest.java (1)

Pattern src/test/java/**/*.java: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_use: enforce_package_rules; db_query_count_tests: track_performance; util_service_factory_pattern: true; avoid_db_access: true; mock_strategy: static_mocks; context_restart_minimize: true

📓 Learnings (1)
src/test/java/de/tum/cit/aet/artemis/iris/IrisExerciseChatSessionIntegrationTest.java (1)
Learnt from: alexjoham
PR: ls1intum/Artemis#9455
File: src/test/java/de/tum/cit/aet/artemis/iris/IrisTextExerciseChatMessageIntegrationTest.java:401-401
Timestamp: 2024-10-15T11:33:17.915Z
Learning: In the Artemis project, when new fields are added to classes like `PyrisChatStatusUpdateDTO`, corresponding tests may be implemented in separate integration test classes such as `IrisChatTokenTrackingIntegrationTest`.

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 23, 2024
coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 23, 2024
@MichaelOwenDyer MichaelOwenDyer changed the title Bugfix: Fix exercise deletion with existing Iris sessions Development: Fix exercise deletion with existing Iris sessions Oct 23, 2024
krusche
krusche previously approved these changes Oct 24, 2024
@krusche krusche dismissed stale reviews from coderabbitai[bot] and themself via 3b584f1 October 24, 2024 06:17
@krusche krusche added ready to merge maintainer-approved The feature maintainer has approved the PR labels Oct 24, 2024
@krusche krusche added this to the 7.6.2 milestone Oct 24, 2024
@krusche krusche merged commit 0745f27 into develop Oct 24, 2024
35 of 41 checks passed
@krusche krusche deleted the bugfix/delete-exercises-with-iris-enabled branch October 24, 2024 06:36
@coderabbitai coderabbitai bot mentioned this pull request Nov 11, 2024
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Pull requests that update the database. (Added Automatically!). Require a CRITICAL deployment. iris Pull requests that affect the corresponding module maintainer-approved The feature maintainer has approved the PR ready to merge tests
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants