diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notification/PushNotificationResourceTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notification/PushNotificationResourceTest.java index 2a310e068f7c..65a2496efcf9 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notification/PushNotificationResourceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notification/PushNotificationResourceTest.java @@ -8,7 +8,6 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.security.test.context.support.WithMockUser; @@ -24,7 +23,6 @@ import de.tum.cit.aet.artemis.core.user.util.UserUtilService; import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest; -@TestInstance(TestInstance.Lifecycle.PER_CLASS) class PushNotificationResourceTest extends AbstractSpringIntegrationIndependentTest { @Autowired diff --git a/src/test/java/de/tum/cit/aet/artemis/programming/icl/LocalVCLocalCIIntegrationTest.java b/src/test/java/de/tum/cit/aet/artemis/programming/icl/LocalVCLocalCIIntegrationTest.java index 1ccdaed26a7f..526d5b8a522f 100644 --- a/src/test/java/de/tum/cit/aet/artemis/programming/icl/LocalVCLocalCIIntegrationTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/programming/icl/LocalVCLocalCIIntegrationTest.java @@ -34,9 +34,12 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.security.test.context.support.WithMockUser; @@ -68,7 +71,18 @@ * This class contains integration tests for the base repositories (template, solution, tests) and the different types of assignment repositories (student assignment, teaching * assistant assignment, instructor assignment). */ + +// TestInstance.Lifecycle.PER_CLASS allows all test methods in this class to share the same instance of the test class. +// This reduces the overhead of repeatedly creating and tearing down a new Spring application context for each test method. +// This is especially useful when the test setup is expensive or when we want to share resources, such as database connections or mock objects, across multiple tests. +// In this case, we want to share the same GitService and UsernamePasswordCredentialsProvider. @TestInstance(TestInstance.Lifecycle.PER_CLASS) + +// ExecutionMode.SAME_THREAD ensures that all tests within this class are executed sequentially in the same thread, rather than in parallel or in a different thread. +// This is important in the context of LocalCI because it avoids potential race conditions or inconsistencies that could arise if multiple test methods are executed +// concurrently. For example, it prevents overloading the LocalCI's result processing system with too many build job results at the same time, which could lead to flaky tests +// or timeouts. By keeping everything in the same thread, we maintain more predictable and stable test behavior, while not increasing the test execution time significantly. +@Execution(ExecutionMode.SAME_THREAD) class LocalVCLocalCIIntegrationTest extends AbstractLocalCILocalVCIntegrationTest { private static final Logger log = LoggerFactory.getLogger(LocalVCLocalCIIntegrationTest.class); @@ -86,6 +100,7 @@ class LocalVCLocalCIIntegrationTest extends AbstractLocalCILocalVCIntegrationTes private SharedQueueProcessingService sharedQueueProcessingService; @Autowired + @Qualifier("hazelcastInstance") private HazelcastInstance hazelcastInstance; @Value("${artemis.user-management.internal-admin.username}") diff --git a/src/test/java/de/tum/cit/aet/artemis/programming/icl/ProgrammingExerciseLocalVCLocalCIIntegrationTest.java b/src/test/java/de/tum/cit/aet/artemis/programming/icl/ProgrammingExerciseLocalVCLocalCIIntegrationTest.java index 97f9162280f8..e54b25a55283 100644 --- a/src/test/java/de/tum/cit/aet/artemis/programming/icl/ProgrammingExerciseLocalVCLocalCIIntegrationTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/programming/icl/ProgrammingExerciseLocalVCLocalCIIntegrationTest.java @@ -24,6 +24,8 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; @@ -48,7 +50,17 @@ import de.tum.cit.aet.artemis.programming.util.ProgrammingExerciseUtilService; import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationLocalCILocalVCTest; +// TestInstance.Lifecycle.PER_CLASS allows all test methods in this class to share the same instance of the test class. +// This reduces the overhead of repeatedly creating and tearing down a new Spring application context for each test method. +// This is especially useful when the test setup is expensive or when we want to share resources, such as database connections or mock objects, across multiple tests. +// In this case, we want to share the same GitService and UsernamePasswordCredentialsProvider. @TestInstance(TestInstance.Lifecycle.PER_CLASS) + +// ExecutionMode.SAME_THREAD ensures that all tests within this class are executed sequentially in the same thread, rather than in parallel or in a different thread. +// This is important in the context of LocalCI because it avoids potential race conditions or inconsistencies that could arise if multiple test methods are executed +// concurrently. For example, it prevents overloading the LocalCI's result processing system with too many build job results at the same time, which could lead to flaky tests +// or timeouts. By keeping everything in the same thread, we maintain more predictable and stable test behavior, while not increasing the test execution time significantly. +@Execution(ExecutionMode.SAME_THREAD) class ProgrammingExerciseLocalVCLocalCIIntegrationTest extends AbstractSpringIntegrationLocalCILocalVCTest { private static final String TEST_PREFIX = "progexlocalvclocalci";