Workaround lack of internal retry on transaction rollback
The get endpoint for key fetching can fail if the transaction cannot complete because of simultaneous modification. Clients currently receive 500 from this and retry if it happens, but this test case runs into it without retrying and then complains that not all the threads completed successfully. This workaround adds some retry attempts.
This commit is contained in:
parent
50ccfee201
commit
0c495e7e72
|
@ -3,16 +3,16 @@ package org.whispersystems.textsecuregcm.tests.storage;
|
|||
import com.opentable.db.postgres.embedded.LiquibasePreparer;
|
||||
import com.opentable.db.postgres.junit.EmbeddedPostgresRules;
|
||||
import com.opentable.db.postgres.junit.PreparedDbRule;
|
||||
import org.jdbi.v3.core.HandleCallback;
|
||||
import io.github.resilience4j.circuitbreaker.CircuitBreakerOpenException;
|
||||
import org.jdbi.v3.core.HandleConsumer;
|
||||
import org.jdbi.v3.core.Jdbi;
|
||||
import org.jdbi.v3.core.statement.UnableToExecuteStatementException;
|
||||
import org.jdbi.v3.core.transaction.SerializableTransactionRunner;
|
||||
import org.jdbi.v3.core.transaction.TransactionException;
|
||||
import org.jdbi.v3.core.transaction.TransactionIsolationLevel;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.postgresql.util.PSQLException;
|
||||
import org.whispersystems.textsecuregcm.configuration.CircuitBreakerConfiguration;
|
||||
import org.whispersystems.textsecuregcm.entities.PreKey;
|
||||
import org.whispersystems.textsecuregcm.storage.FaultTolerantDatabase;
|
||||
|
@ -25,7 +25,6 @@ import java.sql.SQLException;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import io.github.resilience4j.circuitbreaker.CircuitBreakerOpenException;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
|
@ -246,7 +245,18 @@ public class KeysTest {
|
|||
|
||||
for (int i=0;i<20;i++) {
|
||||
Thread thread = new Thread(() -> {
|
||||
List<KeyRecord> results = keys.get("+14152222222");
|
||||
List<KeyRecord> results = null;
|
||||
final int MAX_RETRIES = 5;
|
||||
for (int retryAttempt = 0; results == null && retryAttempt < MAX_RETRIES; ++retryAttempt) {
|
||||
try {
|
||||
results = keys.get("+14152222222");
|
||||
} catch (UnableToExecuteStatementException e) {
|
||||
if (retryAttempt == MAX_RETRIES - 1) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
assertThat(results).isNotNull();
|
||||
assertThat(results.size()).isEqualTo(2);
|
||||
});
|
||||
thread.start();
|
||||
|
|
Loading…
Reference in New Issue