From e72e2efb4a90bd3a1f2b93344878d21a875ad2a3 Mon Sep 17 00:00:00 2001 From: Patrick Bassner Date: Thu, 27 Nov 2025 13:57:15 +0100 Subject: [PATCH] Development: Fix flaky LectureIntegrationTest The test testCreateLectureSeriesAndCorrectLectureAndChannelNames was flaky because course1.getLectures() returns a Set with non-deterministic iteration order. This caused lecture1 and lecture2 to be assigned inconsistently between test runs, leading to ~50% failure rate. Fix: Sort lectures by startDate before assigning to ensure consistent assignment of lecture1 (earlier date) and lecture2 (later date). --- .../artemis/lecture/LectureIntegrationTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/java/de/tum/cit/aet/artemis/lecture/LectureIntegrationTest.java b/src/test/java/de/tum/cit/aet/artemis/lecture/LectureIntegrationTest.java index be2511ca4b98..0954601ac721 100644 --- a/src/test/java/de/tum/cit/aet/artemis/lecture/LectureIntegrationTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/lecture/LectureIntegrationTest.java @@ -118,7 +118,7 @@ void initTestCase() throws Exception { List courses = courseUtilService.createCoursesWithExercisesAndLectures(TEST_PREFIX, true, true, numberOfTutors); this.course1 = this.courseRepository.findByIdWithExercisesAndExerciseDetailsAndLecturesElseThrow(courses.getFirst().getId()); - var lectures = this.course1.getLectures().stream().toList(); + var lectures = this.course1.getLectures().stream().sorted(Comparator.comparing(Lecture::getStartDate)).toList(); createChannelsForLectures(lectures); lecture2.setIsTutorialLecture(true); @@ -544,12 +544,12 @@ void testCreateLectureSeriesAndCorrectLectureAndChannelNames() throws Exception request.postWithoutResponseBody("/api/lecture/courses/" + course1.getId() + "/lectures", List.of(dto1, dto2), HttpStatus.NO_CONTENT); - List lectures = lectureRepository.findAllByCourseId(course1.getId()).stream().sorted(Comparator.comparing(Lecture::getStartDate)).toList(); - assertThat(lectures).hasSize(4); - Lecture firstLecture = lectures.getFirst(); - Lecture secondLecture = lectures.get(1); - Lecture thirdLecture = lectures.get(2); - Lecture fourthLecture = lectures.get(3); + List lecturesAfter = lectureRepository.findAllByCourseId(course1.getId()).stream().sorted(Comparator.comparing(Lecture::getStartDate)).toList(); + assertThat(lecturesAfter).hasSize(4); + Lecture firstLecture = lecturesAfter.getFirst(); + Lecture secondLecture = lecturesAfter.get(1); + Lecture thirdLecture = lecturesAfter.get(2); + Lecture fourthLecture = lecturesAfter.get(3); assertThat(firstLecture.getTitle()).isEqualTo(titleNewLecture1); assertThat(firstLecture.getStartDate().toInstant()).isEqualTo(startNewLecture1.toInstant()); @@ -564,7 +564,7 @@ void testCreateLectureSeriesAndCorrectLectureAndChannelNames() throws Exception Set channels = channelRepository.findLectureChannelsByCourseId(course1.getId()); - assertThat(channels.stream().map(Channel::getLecture).collect(Collectors.toSet())).containsExactlyInAnyOrderElementsOf(lectures); + assertThat(channels.stream().map(Channel::getLecture).collect(Collectors.toSet())).containsExactlyInAnyOrderElementsOf(lecturesAfter); Map lectureIdToChannelMap = channels.stream().collect(Collectors.toMap(channel -> channel.getLecture().getId(), Function.identity())); Channel firstLectureChannel = lectureIdToChannelMap.get(firstLecture.getId());