Fix auto-adding reviewers during push

When we converted ReceiveCommits to use BatchUpdate's parallel
functionality in I40545a4d, we lost the automatic request scope
propagation. This was mostly fine, with the notable exception of:
 - pushing a new patch set of an existing change, and
 - pushing multiple changes so work is in a background thread, and
 - mentioning a user in a footer (Signed-Off-By, etc.), and
 - not including an email address in that footer, and
 - not having the account index enabled.

This would cause AccountResolver to try to call its
Provider<ReviewDb>, which fails because it's not in request scope.

Fix this by passing a ReviewDb into AccountResolver methods. That was
the easy part; the hard part was figuring out how to write a test case
that triggered this. Since the account index is now enabled by
default, this means putting a test-only hack into LuceneIndexModule
to support disabling a specific index. (This could also be useful for
other tests, since we currently don't exercise the non-index
fallbacks.)

Change-Id: I7231be3ea4660c9ee27f09994706b39ee622488a
This commit is contained in:
Dave Borowitz
2016-08-12 16:46:55 -04:00
committed by David Pursehouse
parent 9494ca8720
commit 040c39bcb3
13 changed files with 200 additions and 86 deletions

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.server.args4j;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.account.AccountException;
import com.google.gerrit.server.account.AccountManager;
import com.google.gerrit.server.account.AccountResolver;
@@ -23,6 +24,7 @@ import com.google.gerrit.server.account.AuthRequest;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import org.kohsuke.args4j.CmdLineException;
@@ -35,29 +37,34 @@ import org.kohsuke.args4j.spi.Setter;
import java.io.IOException;
public class AccountIdHandler extends OptionHandler<Account.Id> {
private final Provider<ReviewDb> db;
private final AccountResolver accountResolver;
private final AccountManager accountManager;
private final AuthType authType;
@Inject
public AccountIdHandler(final AccountResolver accountResolver,
final AccountManager accountManager,
final AuthConfig authConfig,
@Assisted final CmdLineParser parser, @Assisted final OptionDef option,
@Assisted final Setter<Account.Id> setter) {
public AccountIdHandler(
Provider<ReviewDb> db,
AccountResolver accountResolver,
AccountManager accountManager,
AuthConfig authConfig,
@Assisted CmdLineParser parser,
@Assisted OptionDef option,
@Assisted Setter<Account.Id> setter) {
super(parser, option, setter);
this.db = db;
this.accountResolver = accountResolver;
this.accountManager = accountManager;
this.authType = authConfig.getAuthType();
}
@Override
public final int parseArguments(final Parameters params)
public int parseArguments(Parameters params)
throws CmdLineException {
final String token = params.getParameter(0);
final Account.Id accountId;
String token = params.getParameter(0);
Account.Id accountId;
try {
final Account a = accountResolver.find(token);
Account a = accountResolver.find(db.get(), token);
if (a != null) {
accountId = a.getId();
} else {