summary refs log tree commit diff
diff options
context:
space:
mode:
authorAmber Brown <hawkowl@atleastfornow.net>2018-10-02 22:53:47 +1000
committerGitHub <noreply@github.com>2018-10-02 22:53:47 +1000
commit7232917f12460efa2e3579331b6a97f046afe90b (patch)
treef74e0fa7eb25660d10df412f7293822e0ebedd6d
parentMerge pull request #3990 from matrix-org/erikj/fix_logging_lost_connection (diff)
downloadsynapse-7232917f12460efa2e3579331b6a97f046afe90b.tar.xz
Disable frozen dicts by default (#3987)
-rw-r--r--changelog.d/3987.misc1
-rw-r--r--synapse/events/__init__.py13
-rw-r--r--tests/replication/slave/storage/test_events.py6
-rw-r--r--tests/utils.py3
4 files changed, 18 insertions, 5 deletions
diff --git a/changelog.d/3987.misc b/changelog.d/3987.misc
new file mode 100644
index 0000000000..d6b5016211
--- /dev/null
+++ b/changelog.d/3987.misc
@@ -0,0 +1 @@
+Disable USE_FROZEN_DICTS for unittests by default.
diff --git a/synapse/events/__init__.py b/synapse/events/__init__.py
index b782af6308..12f1eb0a3e 100644
--- a/synapse/events/__init__.py
+++ b/synapse/events/__init__.py
@@ -13,15 +13,22 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import os
+from distutils.util import strtobool
+
 import six
 
 from synapse.util.caches import intern_dict
 from synapse.util.frozenutils import freeze
 
 # Whether we should use frozen_dict in FrozenEvent. Using frozen_dicts prevents
-# bugs where we accidentally share e.g. signature dicts. However, converting
-# a dict to frozen_dicts is expensive.
-USE_FROZEN_DICTS = True
+# bugs where we accidentally share e.g. signature dicts. However, converting a
+# dict to frozen_dicts is expensive.
+#
+# NOTE: This is overridden by the configuration by the Synapse worker apps, but
+# for the sake of tests, it is set here while it cannot be configured on the
+# homeserver object itself.
+USE_FROZEN_DICTS = strtobool(os.environ.get("SYNAPSE_USE_FROZEN_DICTS", "0"))
 
 
 class _EventInternalMetadata(object):
diff --git a/tests/replication/slave/storage/test_events.py b/tests/replication/slave/storage/test_events.py
index db44d33c68..41be5d5a1a 100644
--- a/tests/replication/slave/storage/test_events.py
+++ b/tests/replication/slave/storage/test_events.py
@@ -12,6 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from canonicaljson import encode_canonical_json
+
 from synapse.events import FrozenEvent, _EventInternalMetadata
 from synapse.events.snapshot import EventContext
 from synapse.replication.slave.storage.events import SlavedEventStore
@@ -26,7 +28,9 @@ ROOM_ID = "!room:blue"
 
 
 def dict_equals(self, other):
-    return self.__dict__ == other.__dict__
+    me = encode_canonical_json(self._event_dict)
+    them = encode_canonical_json(other._event_dict)
+    return me == them
 
 
 def patch__eq__(cls):
diff --git a/tests/utils.py b/tests/utils.py
index 1ef80e7b79..dd347a0c59 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -136,6 +136,8 @@ def default_config(name):
     config.rc_messages_per_second = 10000
     config.rc_message_burst_count = 10000
 
+    config.use_frozen_dicts = False
+
     # we need a sane default_room_version, otherwise attempts to create rooms will
     # fail.
     config.default_room_version = "1"
@@ -182,7 +184,6 @@ def setup_test_homeserver(
     if config is None:
         config = default_config(name)
 
-    config.use_frozen_dicts = True
     config.ldap_enabled = False
 
     if "clock" not in kargs: