Always clear ofy session cache in command tests

The previous code would not execute after failure tests that ended
with thrown exceptions, potentially causing issues with post-run
verification inside of tests.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=117484219
This commit is contained in:
mcilwain 2016-03-17 14:16:54 -07:00 committed by Justine Tunney
parent 99a50f7972
commit 14c794aa45

View file

@ -76,14 +76,17 @@ public abstract class CommandTestCase<C extends Command> {
void runCommand(String... args) throws Exception {
RegistryToolEnvironment.UNITTEST.setup();
try {
JCommander jcommander = new JCommander(command);
jcommander.addConverterFactory(new ParameterFactory());
jcommander.parse(args);
command.run();
} finally {
// Clear the session cache so that subsequent reads for verification purposes hit datastore.
// This primarily matters for AutoTimestamp fields, which otherwise won't have updated values.
ofy().clearSessionCache();
}
}
/** Adds "--force" as the first parameter, then runs the command. */
void runCommandForced(String... args) throws Exception {