Disable frozen dicts by default (#3987)

This commit is contained in:
Amber Brown 2018-10-02 22:53:47 +10:00 committed by GitHub
parent 0f7033fb98
commit 7232917f12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 5 deletions

1
changelog.d/3987.misc Normal file
View File

@ -0,0 +1 @@
Disable USE_FROZEN_DICTS for unittests by default.

View File

@ -13,15 +13,22 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import os
from distutils.util import strtobool
import six import six
from synapse.util.caches import intern_dict from synapse.util.caches import intern_dict
from synapse.util.frozenutils import freeze from synapse.util.frozenutils import freeze
# Whether we should use frozen_dict in FrozenEvent. Using frozen_dicts prevents # Whether we should use frozen_dict in FrozenEvent. Using frozen_dicts prevents
# bugs where we accidentally share e.g. signature dicts. However, converting # bugs where we accidentally share e.g. signature dicts. However, converting a
# a dict to frozen_dicts is expensive. # dict to frozen_dicts is expensive.
USE_FROZEN_DICTS = True #
# 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): class _EventInternalMetadata(object):

View File

@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from canonicaljson import encode_canonical_json
from synapse.events import FrozenEvent, _EventInternalMetadata from synapse.events import FrozenEvent, _EventInternalMetadata
from synapse.events.snapshot import EventContext from synapse.events.snapshot import EventContext
from synapse.replication.slave.storage.events import SlavedEventStore from synapse.replication.slave.storage.events import SlavedEventStore
@ -26,7 +28,9 @@ ROOM_ID = "!room:blue"
def dict_equals(self, other): 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): def patch__eq__(cls):

View File

@ -136,6 +136,8 @@ def default_config(name):
config.rc_messages_per_second = 10000 config.rc_messages_per_second = 10000
config.rc_message_burst_count = 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 # we need a sane default_room_version, otherwise attempts to create rooms will
# fail. # fail.
config.default_room_version = "1" config.default_room_version = "1"
@ -182,7 +184,6 @@ def setup_test_homeserver(
if config is None: if config is None:
config = default_config(name) config = default_config(name)
config.use_frozen_dicts = True
config.ldap_enabled = False config.ldap_enabled = False
if "clock" not in kargs: if "clock" not in kargs: