From 14c794aa45d91b7063950c9b45f1ec16a41ef48a Mon Sep 17 00:00:00 2001 From: mcilwain Date: Thu, 17 Mar 2016 14:16:54 -0700 Subject: [PATCH] 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 --- .../domain/registry/tools/CommandTestCase.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/javatests/com/google/domain/registry/tools/CommandTestCase.java b/javatests/com/google/domain/registry/tools/CommandTestCase.java index d895652b8..56637faea 100644 --- a/javatests/com/google/domain/registry/tools/CommandTestCase.java +++ b/javatests/com/google/domain/registry/tools/CommandTestCase.java @@ -76,13 +76,16 @@ public abstract class CommandTestCase { void runCommand(String... args) throws Exception { RegistryToolEnvironment.UNITTEST.setup(); - JCommander jcommander = new JCommander(command); - jcommander.addConverterFactory(new ParameterFactory()); - jcommander.parse(args); - command.run(); - // 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(); + 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. */