Skip to content

Commit

Permalink
Make test more stable
Browse files Browse the repository at this point in the history
  • Loading branch information
npomaroli committed Jul 26, 2023
1 parent 08c2275 commit 2222c34
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
15 changes: 15 additions & 0 deletions tests/common/src/main/java/com/gentics/mesh/test/ClientHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static org.junit.Assert.fail;

import java.util.Locale;
import java.util.Objects;
import java.util.function.Function;

import com.gentics.mesh.core.data.i18n.I18NUtil;
Expand Down Expand Up @@ -246,4 +247,18 @@ public static void expectFailureMessage(Throwable e, HttpResponseStatus status,
fail("Unhandled exception");
}
}

public static boolean isFailureMessage(Throwable e, HttpResponseStatus status) {
if (e instanceof GenericRestException) {
GenericRestException exception = (GenericRestException) e;
return Objects.equals(status, exception.getStatus());
} else if (e instanceof MeshRestClientMessageException) {
MeshRestClientMessageException exception = (MeshRestClientMessageException) e;
return Objects.equals(status.code(), exception.getStatusCode());
} else if (e != null && e.getCause() != null && e.getCause() != e) {
return isFailureMessage(e.getCause(), status);
} else {
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
package com.gentics.mesh.core.project;

import static com.gentics.mesh.test.ClientHelper.call;
import static com.gentics.mesh.test.ClientHelper.isFailureMessage;
import static com.gentics.mesh.test.ElasticsearchTestMode.TRACKING;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.concurrent.TimeoutException;

import org.junit.Test;

import com.gentics.mesh.core.rest.project.ProjectResponse;
import com.gentics.mesh.test.MeshTestSetting;
import com.gentics.mesh.test.TestSize;

import io.netty.handler.codec.http.HttpResponseStatus;

@MeshTestSetting(elasticsearch = TRACKING, testSize = TestSize.FULL, startServer = true)
public class OrientDBProjectEndpointTest extends ProjectEndpointTest {


/**
* Test renaming, deleting and re-creating a project (together with project name cache).
* @throws InterruptedException
* @throws TimeoutException
*/
@Test
public void testRenameDeleteCreateProject() {
public void testRenameDeleteCreateProject() throws InterruptedException, TimeoutException {
// create project named "project"
ProjectResponse project = createProject("project");

Expand All @@ -30,8 +37,25 @@ public void testRenameDeleteCreateProject() {
project = updateProject(project.getUuid(), "newproject");
assertThat(mesh().projectNameCache().size()).as("Project name cache size").isEqualTo(0);

long maxWaitMs = 1000;
long delayMs = 100;
boolean repeat = false;

// get tag families of newproject (this will put project into cache)
call(() -> client().findTagFamilies("newproject"));
long start = System.currentTimeMillis();
do {
try {
call(() -> client().findTagFamilies("newproject"));
repeat = false;
} catch (Throwable t) {
if (isFailureMessage(t, HttpResponseStatus.NOT_FOUND) && (System.currentTimeMillis() - start) < maxWaitMs) {
Thread.sleep(delayMs);
repeat = true;
} else {
throw t;
}
}
} while (repeat);
assertThat(mesh().projectNameCache().size()).as("Project name cache size").isEqualTo(1);

// delete "newproject"
Expand Down

0 comments on commit 2222c34

Please sign in to comment.