mirror of
https://github.com/google/nomulus
synced 2026-06-09 08:22:59 +00:00
Fix flaky tests due to Entity name conflicts (#569)
* Fix flaky tests due to Entity name conflicts Objectify siliently replaces current registration of a given kind when another class is registered for this kind. There are several TestObject classes in the current code base, which by default are all mapped to the same kind. Tests have only been flaky because impacted tests need to run in specific orders for failures to happen. Using multiple executors in Gradle also reduced the likely hood of errors. To reproduce the problem run the following tests in order (e.g., by putting them in a test suite): 1. ExportCommitLogDiffActionTest 2. CreateAutoTimestampTest 3. RestoreCommitLogsActionTest In this PR, we - Made sure all entities have unique kinds. - Made all test entities register with AppEngineRule instead of directly with ObjectifyService. - Added code in AppEngineRule to check for re-registrations. - Added presumit check for forbidden direct registration.
This commit is contained in:
@@ -151,11 +151,14 @@ public class ObjectifyService {
|
||||
String kind = Key.getKind(clazz);
|
||||
boolean registered = factory().getMetadata(kind) != null;
|
||||
if (clazz.isAnnotationPresent(Entity.class)) {
|
||||
// Objectify silently ignores re-registrations for a given kind string, even if the classes
|
||||
// being registered are distinct. Throw an exception if that would happen here.
|
||||
checkState(!registered,
|
||||
// Objectify silently replaces current registration for a given kind string when a different
|
||||
// class is registered again for this kind. For simplicity's sake, throw an exception on any
|
||||
// re-registration.
|
||||
checkState(
|
||||
!registered,
|
||||
"Kind '%s' already registered, cannot register new @Entity %s",
|
||||
kind, clazz.getCanonicalName());
|
||||
kind,
|
||||
clazz.getCanonicalName());
|
||||
} else if (clazz.isAnnotationPresent(EntitySubclass.class)) {
|
||||
// Ensure that any @EntitySubclass classes have also had their parent @Entity registered,
|
||||
// which Objectify nominally requires but doesn't enforce in 4.x (though it may in 5.x).
|
||||
|
||||
Reference in New Issue
Block a user