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: Cleanup temporary files when running tests #7234

Merged
merged 6 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ void initTestCase() throws Exception {
@AfterEach
void tearDown() throws Exception {
programmingExerciseTestService.tearDown();
for (LocalRepository studentRepo : studentRepos) {
studentRepo.resetLocalRepo();
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ void testGetStudentExamForConduction_testExam() throws Exception {
// TODO: test the conduction / submission of the test exams, in particular that the summary includes all submissions

deleteExamWithInstructor(testExam1);
repo.resetLocalRepo();
}

private void assertParticipationAndSubmissions(StudentExam response, User user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void init() throws Exception {
}

@AfterEach
void tearDown() throws InterruptedException {
void tearDown() throws Exception {
// not yet finished scheduled futures may otherwise affect following tests
scheduleService.clearAllTasks();

Expand All @@ -124,6 +124,7 @@ void tearDown() throws InterruptedException {

bambooRequestMockProvider.reset();
bitbucketRequestMockProvider.reset();
studentRepository.resetLocalRepo();
}

private void verifyLockStudentRepositoryAndParticipationOperation(boolean wasCalled, long timeoutInMs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class RepositoryIntegrationTest extends AbstractSpringIntegrationBambooBitbucket

private final LocalRepository studentRepository = new LocalRepository(defaultBranch);

private LocalRepository templateRepository;

private final List<BuildLogEntry> logs = new ArrayList<>();

private final BuildLogEntry buildLogEntry = new BuildLogEntry(ZonedDateTime.now(), "Checkout to revision e65aa77cc0380aeb9567ccceb78aca416d86085b has failed.");
Expand Down Expand Up @@ -184,7 +186,7 @@ void setup() throws Exception {
programmingExercise.setTestRepositoryUrl(localRepoUrl.toString());

// Create template repo
LocalRepository templateRepository = new LocalRepository(defaultBranch);
templateRepository = new LocalRepository(defaultBranch);
templateRepository.configureRepos("templateLocalRepo", "templateOriginRepo");

// add file to the template repo folder
Expand Down Expand Up @@ -240,6 +242,7 @@ void setup() throws Exception {
void tearDown() throws IOException {
reset(gitService);
studentRepository.resetLocalRepo();
templateRepository.resetLocalRepo();
}

@Test
Expand Down Expand Up @@ -631,6 +634,7 @@ void testSaveFilesAfterDueDateAsInstructor() throws Exception {
.getOrCheckoutRepository(instructorAssignmentParticipation.getVcsRepositoryUrl(), true, defaultBranch);

request.put(studentRepoBaseUrl + instructorAssignmentParticipation.getId() + "/files?commit=true", List.of(), HttpStatus.OK);
instructorAssignmentRepository.resetLocalRepo();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.ZonedDateTime;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -53,6 +54,12 @@ void initTestCase() throws Exception {
exercise = ProgrammingExerciseFactory.generateProgrammingExercise(ZonedDateTime.now().minusDays(1), ZonedDateTime.now().plusDays(7), course);
}

@AfterEach
void cleanup() throws Exception {
solutionRepo.resetLocalRepo();
templateRepo.resetLocalRepo();
}

@Test
@WithMockUser(username = TEST_PREFIX + "student1", roles = "USER")
void getGitDiffAsAStudent() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -67,6 +69,12 @@ void initTestCase() {
exercise = exerciseUtilService.getFirstExerciseWithType(course, ProgrammingExercise.class);
}

@AfterEach
void cleanup() throws IOException {
templateRepo.resetLocalRepo();
solutionRepo.resetLocalRepo();
}

@Test
@WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR")
void updateGitDiffNoChanges() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

import java.io.IOException;
import java.time.ZonedDateTime;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -61,6 +63,12 @@ void initTestCase() {
exercise = ProgrammingExerciseFactory.generateProgrammingExercise(ZonedDateTime.now().minusDays(1), ZonedDateTime.now().plusDays(7), course);
}

@AfterEach
void cleanup() throws IOException {
solutionRepo.resetLocalRepo();
testRepo.resetLocalRepo();
}

private void addTestCaseToExercise(String name) {
var testCase = new ProgrammingExerciseTestCase();
testCase.setTestName(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import static org.assertj.core.api.Assertions.*;

import java.io.IOException;
import java.util.Map;
import java.util.Set;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -80,6 +82,11 @@ void setup() throws Exception {
programmingExercise = programmingExerciseRepository.findByIdElseThrow(programmingExercise.getId());
}

@AfterEach
void cleanup() throws IOException {
solutionRepo.resetLocalRepo();
}

@Test
@WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR")
void shouldCreateFullTestwiseCoverageReport() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.util.HashSet;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;

Expand Down Expand Up @@ -80,6 +79,11 @@ void initTestCase() throws Exception {
exercise.setTestwiseCoverageEnabled(true);
}

@AfterEach
void cleanup() throws IOException {
solutionRepo.resetLocalRepo();
}

private ProgrammingExerciseTestCase addTestCaseToExercise(String name) {
var testCase = new ProgrammingExerciseTestCase();
testCase.setTestName(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class IrisMessageIntegrationTest extends AbstractIrisIntegrationTest {

private ProgrammingExercise exercise;

private LocalRepository repository;

@BeforeEach
void initTestCase() {
userUtilService.addUsers(TEST_PREFIX, 2, 0, 0, 0);
Expand All @@ -59,6 +61,7 @@ void initTestCase() {
exercise = exerciseUtilService.getFirstExerciseWithType(course, ProgrammingExercise.class);
activateIrisFor(course);
activateIrisFor(exercise);
repository = new LocalRepository("main");
}

@Test
Expand All @@ -69,9 +72,9 @@ void sendOneMessage() throws Exception {
messageToSend.setMessageDifferentiator(1453);

irisRequestMockProvider.mockMessageResponse("Hello World");
var savedExercise = irisUtilTestService.setupTemplate(exercise, new LocalRepository("main"));
var savedExercise = irisUtilTestService.setupTemplate(exercise, repository);
var exerciseParticipation = participationUtilService.addStudentParticipationForProgrammingExercise(savedExercise, TEST_PREFIX + "student1");
irisUtilTestService.setupStudentParticipation(exerciseParticipation, new LocalRepository("main"));
irisUtilTestService.setupStudentParticipation(exerciseParticipation, repository);
activateIrisFor(savedExercise);

var irisMessage = request.postWithResponseBody("/api/iris/sessions/" + irisSession.getId() + "/messages", messageToSend, IrisMessage.class, HttpStatus.CREATED);
Expand Down Expand Up @@ -115,9 +118,9 @@ void sendTwoMessages() throws Exception {
var irisSession = irisSessionService.createChatSessionForProgrammingExercise(exercise, userUtilService.getUserByLogin(TEST_PREFIX + "student1"));
IrisMessage messageToSend1 = createDefaultMockMessage(irisSession);

var savedExercise = irisUtilTestService.setupTemplate(exercise, new LocalRepository("main"));
var savedExercise = irisUtilTestService.setupTemplate(exercise, repository);
var exerciseParticipation = participationUtilService.addStudentParticipationForProgrammingExercise(savedExercise, TEST_PREFIX + "student1");
irisUtilTestService.setupStudentParticipation(exerciseParticipation, new LocalRepository("main"));
irisUtilTestService.setupStudentParticipation(exerciseParticipation, repository);
activateIrisFor(savedExercise);

var irisMessage1 = request.postWithResponseBody("/api/iris/sessions/" + irisSession.getId() + "/messages", messageToSend1, IrisMessage.class, HttpStatus.CREATED);
Expand Down Expand Up @@ -239,9 +242,9 @@ void sendOneMessageBadRequest() throws Exception {
IrisMessage messageToSend = createDefaultMockMessage(irisSession);

irisRequestMockProvider.mockMessageError();
var savedExercise = irisUtilTestService.setupTemplate(exercise, new LocalRepository("main"));
var savedExercise = irisUtilTestService.setupTemplate(exercise, repository);
var exerciseParticipation = participationUtilService.addStudentParticipationForProgrammingExercise(savedExercise, TEST_PREFIX + "student1");
irisUtilTestService.setupStudentParticipation(exerciseParticipation, new LocalRepository("main"));
irisUtilTestService.setupStudentParticipation(exerciseParticipation, repository);
activateIrisFor(savedExercise);

request.postWithResponseBody("/api/iris/sessions/" + irisSession.getId() + "/messages", messageToSend, IrisMessage.class, HttpStatus.CREATED);
Expand All @@ -259,9 +262,9 @@ void sendOneMessageEmptyBody() throws Exception {
IrisMessage messageToSend = createDefaultMockMessage(irisSession);

irisRequestMockProvider.mockMessageResponse(null);
var savedExercise = irisUtilTestService.setupTemplate(exercise, new LocalRepository("main"));
var savedExercise = irisUtilTestService.setupTemplate(exercise, repository);
var exerciseParticipation = participationUtilService.addStudentParticipationForProgrammingExercise(savedExercise, TEST_PREFIX + "student1");
irisUtilTestService.setupStudentParticipation(exerciseParticipation, new LocalRepository("main"));
irisUtilTestService.setupStudentParticipation(exerciseParticipation, repository);
activateIrisFor(savedExercise);

request.postWithResponseBody("/api/iris/sessions/" + irisSession.getId() + "/messages", messageToSend, IrisMessage.class, HttpStatus.CREATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ void testFetchPush_repositoryDoesNotExist() throws IOException, GitAPIException,
localVCLocalCITestService.testPushReturnsError(someRepository.localGit, student1Login, projectKey, repositorySlug, NOT_FOUND);

// Cleanup
someRepository.localGit.close();
FileUtils.deleteDirectory(someRepository.localRepoFile);
someRepository.resetLocalRepo();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ void testFetch_studentAssignmentRepository_teamMode_afterDueDate() throws Except
// Instructor should be able to read and write.
localVCLocalCITestService.testFetchSuccessful(teamLocalRepository.localGit, instructor1Login, projectKey1, teamRepositorySlug);
localVCLocalCITestService.testPushSuccessful(teamLocalRepository.localGit, instructor1Login, projectKey1, teamRepositorySlug);
teamLocalRepository.resetLocalRepo();
}

private LocalRepository prepareTeamExerciseAndRepository() throws GitAPIException, IOException, URISyntaxException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ private void prepareMocksForProgrammingExercise(String userLogin, boolean practi
var repo = new LocalRepository(defaultBranch);
repo.configureRepos("studentRepo", "studentOriginRepo");
programmingExerciseTestService.setupRepositoryMocksParticipant(programmingExercise, userLogin, repo, practiceMode);
repo.resetLocalRepo();
}

@Test
Expand Down Expand Up @@ -492,6 +493,7 @@ void requestFeedbackScoreNotFull() throws Exception {

request.putWithResponseBody("/api/exercises/" + programmingExercise.getId() + "/request-feedback", null, ProgrammingExerciseStudentParticipation.class,
HttpStatus.BAD_REQUEST);
localRepo.resetLocalRepo();
}

@Test
Expand Down Expand Up @@ -547,6 +549,7 @@ void requestFeedbackSuccess() throws Exception {
assertThat(response.getIndividualDueDate()).isNotNull().isBefore(ZonedDateTime.now());

verify(programmingExerciseParticipationService).lockStudentRepositoryAndParticipation(programmingExercise, participation);
localRepo.resetLocalRepo();
}

@Test
Expand All @@ -562,6 +565,7 @@ void resumeProgrammingExerciseParticipation() throws Exception {
var updatedParticipation = request.putWithResponseBody("/api/exercises/" + programmingExercise.getId() + "/resume-programming-participation/" + participation.getId(), null,
ProgrammingExerciseStudentParticipation.class, HttpStatus.OK);
assertThat(updatedParticipation.getInitializationState()).isEqualTo(InitializationState.INITIALIZED);
localRepo.resetLocalRepo();
}

@Test
Expand Down