Remove @Sandboxed from more tests
Running a test in a sandbox adds about 1s to the test runtime when the test is executed from Eclipse. Saving this time justifies a little effort to avoid running tests in sandboxes. Some tests were annotated with @Sandboxed because they set a global flag. Remove @Sandboxed from these tests and instead use an AutoClosable to unset the flag at the end of the test. Change-Id: Idc77a18dd67a20de2d5ace5cd172b18160bc3724 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -1144,8 +1144,7 @@ public class GroupsIT extends AbstractDaemonTest {
|
|||||||
@Sandboxed
|
@Sandboxed
|
||||||
public void blockReviewDbUpdatesOnGroupCreation() throws Exception {
|
public void blockReviewDbUpdatesOnGroupCreation() throws Exception {
|
||||||
assume().that(groupsInNoteDb()).isFalse();
|
assume().that(groupsInNoteDb()).isFalse();
|
||||||
cfg.setBoolean("user", null, "blockReviewDbGroupUpdates", true);
|
try (AutoCloseable ctx = createBlockReviewDbGroupUpdatesContext()) {
|
||||||
try {
|
|
||||||
gApi.groups().create(name("foo"));
|
gApi.groups().create(name("foo"));
|
||||||
fail("Expected RestApiException: Updates to groups in ReviewDb are blocked");
|
fail("Expected RestApiException: Updates to groups in ReviewDb are blocked");
|
||||||
} catch (RestApiException e) {
|
} catch (RestApiException e) {
|
||||||
@@ -1159,8 +1158,7 @@ public class GroupsIT extends AbstractDaemonTest {
|
|||||||
assume().that(groupsInNoteDb()).isFalse();
|
assume().that(groupsInNoteDb()).isFalse();
|
||||||
String group1 = gApi.groups().create(name("foo")).get().id;
|
String group1 = gApi.groups().create(name("foo")).get().id;
|
||||||
String group2 = gApi.groups().create(name("bar")).get().id;
|
String group2 = gApi.groups().create(name("bar")).get().id;
|
||||||
cfg.setBoolean("user", null, "blockReviewDbGroupUpdates", true);
|
try (AutoCloseable ctx = createBlockReviewDbGroupUpdatesContext()) {
|
||||||
try {
|
|
||||||
gApi.groups().id(group1).addGroups(group2);
|
gApi.groups().id(group1).addGroups(group2);
|
||||||
fail("Expected RestApiException: Updates to groups in ReviewDb are blocked");
|
fail("Expected RestApiException: Updates to groups in ReviewDb are blocked");
|
||||||
} catch (RestApiException e) {
|
} catch (RestApiException e) {
|
||||||
@@ -1367,6 +1365,16 @@ public class GroupsIT extends AbstractDaemonTest {
|
|||||||
return groupsInNoteDb() && cfg.getBoolean(SECTION_NOTE_DB, GROUPS.key(), READ, false);
|
return groupsInNoteDb() && cfg.getBoolean(SECTION_NOTE_DB, GROUPS.key(), READ, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AutoCloseable createBlockReviewDbGroupUpdatesContext() {
|
||||||
|
cfg.setBoolean("user", null, "blockReviewDbGroupUpdates", true);
|
||||||
|
return new AutoCloseable() {
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
cfg.setBoolean("user", null, "blockReviewDbGroupUpdates", false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Target({METHOD})
|
@Target({METHOD})
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
private @interface IgnoreGroupInconsistencies {}
|
private @interface IgnoreGroupInconsistencies {}
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import com.google.common.collect.ImmutableSet;
|
|||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
import com.google.gerrit.acceptance.RestResponse;
|
import com.google.gerrit.acceptance.RestResponse;
|
||||||
import com.google.gerrit.acceptance.Sandboxed;
|
|
||||||
import com.google.gerrit.common.data.GlobalCapability;
|
import com.google.gerrit.common.data.GlobalCapability;
|
||||||
import com.google.gerrit.common.data.Permission;
|
import com.google.gerrit.common.data.Permission;
|
||||||
import com.google.gerrit.extensions.api.config.ConsistencyCheckInfo;
|
import com.google.gerrit.extensions.api.config.ConsistencyCheckInfo;
|
||||||
@@ -815,52 +814,49 @@ public class ExternalIdIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Sandboxed
|
|
||||||
public void checkNoReloadAfterUpdate() throws Exception {
|
public void checkNoReloadAfterUpdate() throws Exception {
|
||||||
Set<ExternalId> expectedExtIds = new HashSet<>(externalIds.byAccount(admin.id));
|
Set<ExternalId> expectedExtIds = new HashSet<>(externalIds.byAccount(admin.id));
|
||||||
externalIdReader.setFailOnLoad(true);
|
try (AutoCloseable ctx = createFailOnLoadContext()) {
|
||||||
|
// insert external ID
|
||||||
|
ExternalId extId = ExternalId.create("foo", "bar", admin.id);
|
||||||
|
extIdsUpdate.create().insert(extId);
|
||||||
|
expectedExtIds.add(extId);
|
||||||
|
assertThat(externalIds.byAccount(admin.id)).containsExactlyElementsIn(expectedExtIds);
|
||||||
|
|
||||||
// insert external ID
|
// update external ID
|
||||||
ExternalId extId = ExternalId.create("foo", "bar", admin.id);
|
expectedExtIds.remove(extId);
|
||||||
extIdsUpdate.create().insert(extId);
|
extId = ExternalId.createWithEmail("foo", "bar", admin.id, "foo.bar@example.com");
|
||||||
expectedExtIds.add(extId);
|
extIdsUpdate.create().upsert(extId);
|
||||||
assertThat(externalIds.byAccount(admin.id)).containsExactlyElementsIn(expectedExtIds);
|
expectedExtIds.add(extId);
|
||||||
|
assertThat(externalIds.byAccount(admin.id)).containsExactlyElementsIn(expectedExtIds);
|
||||||
|
|
||||||
// update external ID
|
// delete external ID
|
||||||
expectedExtIds.remove(extId);
|
extIdsUpdate.create().delete(extId);
|
||||||
extId = ExternalId.createWithEmail("foo", "bar", admin.id, "foo.bar@example.com");
|
expectedExtIds.remove(extId);
|
||||||
extIdsUpdate.create().upsert(extId);
|
assertThat(externalIds.byAccount(admin.id)).containsExactlyElementsIn(expectedExtIds);
|
||||||
expectedExtIds.add(extId);
|
}
|
||||||
assertThat(externalIds.byAccount(admin.id)).containsExactlyElementsIn(expectedExtIds);
|
|
||||||
|
|
||||||
// delete external ID
|
|
||||||
extIdsUpdate.create().delete(extId);
|
|
||||||
expectedExtIds.remove(extId);
|
|
||||||
assertThat(externalIds.byAccount(admin.id)).containsExactlyElementsIn(expectedExtIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Sandboxed
|
|
||||||
public void byAccountFailIfReadingExternalIdsFails() throws Exception {
|
public void byAccountFailIfReadingExternalIdsFails() throws Exception {
|
||||||
externalIdReader.setFailOnLoad(true);
|
try (AutoCloseable ctx = createFailOnLoadContext()) {
|
||||||
|
// update external ID branch so that external IDs need to be reloaded
|
||||||
|
insertExtIdBehindGerritsBack(ExternalId.create("foo", "bar", admin.id));
|
||||||
|
|
||||||
// update external ID branch so that external IDs need to be reloaded
|
exception.expect(IOException.class);
|
||||||
insertExtIdBehindGerritsBack(ExternalId.create("foo", "bar", admin.id));
|
externalIds.byAccount(admin.id);
|
||||||
|
}
|
||||||
exception.expect(IOException.class);
|
|
||||||
externalIds.byAccount(admin.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Sandboxed
|
|
||||||
public void byEmailFailIfReadingExternalIdsFails() throws Exception {
|
public void byEmailFailIfReadingExternalIdsFails() throws Exception {
|
||||||
externalIdReader.setFailOnLoad(true);
|
try (AutoCloseable ctx = createFailOnLoadContext()) {
|
||||||
|
// update external ID branch so that external IDs need to be reloaded
|
||||||
|
insertExtIdBehindGerritsBack(ExternalId.create("foo", "bar", admin.id));
|
||||||
|
|
||||||
// update external ID branch so that external IDs need to be reloaded
|
exception.expect(IOException.class);
|
||||||
insertExtIdBehindGerritsBack(ExternalId.create("foo", "bar", admin.id));
|
externalIds.byEmail(admin.email);
|
||||||
|
}
|
||||||
exception.expect(IOException.class);
|
|
||||||
externalIds.byEmail(admin.email);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -946,4 +942,14 @@ public class ExternalIdIT extends AbstractDaemonTest {
|
|||||||
assertThat(update.getStatus()).isEqualTo(Status.REJECTED_OTHER_REASON);
|
assertThat(update.getStatus()).isEqualTo(Status.REJECTED_OTHER_REASON);
|
||||||
assertThat(update.getMessage()).isEqualTo(msg);
|
assertThat(update.getMessage()).isEqualTo(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AutoCloseable createFailOnLoadContext() {
|
||||||
|
externalIdReader.setFailOnLoad(true);
|
||||||
|
return new AutoCloseable() {
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
externalIdReader.setFailOnLoad(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user