Fix flaky couchbase spring test (#12392)
This commit is contained in:
parent
6d21238592
commit
9f860d90d1
|
@ -14,11 +14,11 @@ import com.couchbase.client.java.view.DefaultView;
|
||||||
import com.couchbase.client.java.view.DesignDocument;
|
import com.couchbase.client.java.view.DesignDocument;
|
||||||
import io.opentelemetry.api.trace.SpanKind;
|
import io.opentelemetry.api.trace.SpanKind;
|
||||||
import io.opentelemetry.instrumentation.couchbase.AbstractCouchbaseTest;
|
import io.opentelemetry.instrumentation.couchbase.AbstractCouchbaseTest;
|
||||||
|
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
|
||||||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
||||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import org.junit.jupiter.api.AfterAll;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
@ -30,6 +30,8 @@ public abstract class AbstractCouchbaseSpringRepositoryTest extends AbstractCouc
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
|
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
|
||||||
|
|
||||||
|
@RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();
|
||||||
|
|
||||||
private ConfigurableApplicationContext applicationContext;
|
private ConfigurableApplicationContext applicationContext;
|
||||||
private TestRepository repository;
|
private TestRepository repository;
|
||||||
|
|
||||||
|
@ -64,11 +66,10 @@ public abstract class AbstractCouchbaseSpringRepositoryTest extends AbstractCouc
|
||||||
repository = applicationContext.getBean(TestRepository.class);
|
repository = applicationContext.getBean(TestRepository.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
private void cleanUpTest() {
|
||||||
void cleanUpTest() {
|
|
||||||
testing.clearData();
|
testing.clearData();
|
||||||
repository.deleteAll();
|
repository.deleteAll();
|
||||||
testing.waitForTraces(1);
|
testing.waitForTraces(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
|
@ -103,6 +104,7 @@ public abstract class AbstractCouchbaseSpringRepositoryTest extends AbstractCouc
|
||||||
void save() {
|
void save() {
|
||||||
TestDocument document = new TestDocument();
|
TestDocument document = new TestDocument();
|
||||||
TestDocument result = repository.save(document);
|
TestDocument result = repository.save(document);
|
||||||
|
cleanup.deferCleanup(this::cleanUpTest);
|
||||||
|
|
||||||
assertThat(result).isEqualTo(document);
|
assertThat(result).isEqualTo(document);
|
||||||
|
|
||||||
|
@ -124,6 +126,7 @@ public abstract class AbstractCouchbaseSpringRepositoryTest extends AbstractCouc
|
||||||
repository.save(document);
|
repository.save(document);
|
||||||
return findById(repository, "1");
|
return findById(repository, "1");
|
||||||
});
|
});
|
||||||
|
cleanup.deferCleanup(this::cleanUpTest);
|
||||||
|
|
||||||
assertThat(result).isEqualTo(document);
|
assertThat(result).isEqualTo(document);
|
||||||
|
|
||||||
|
@ -149,6 +152,7 @@ public abstract class AbstractCouchbaseSpringRepositoryTest extends AbstractCouc
|
||||||
document.setData("other data");
|
document.setData("other data");
|
||||||
repository.save(document);
|
repository.save(document);
|
||||||
});
|
});
|
||||||
|
cleanup.deferCleanup(this::cleanUpTest);
|
||||||
|
|
||||||
testing.waitAndAssertTraces(
|
testing.waitAndAssertTraces(
|
||||||
trace ->
|
trace ->
|
||||||
|
|
Loading…
Reference in New Issue