Merge changes from master

This commit is contained in:
Griatch 2020-07-15 18:07:45 +02:00
commit 94cf728081
24 changed files with 324 additions and 244 deletions

View file

@ -13,6 +13,7 @@ import time
from os.path import dirname, abspath
from twisted.application import internet, service
from twisted.internet.task import LoopingCall
from twisted.internet import protocol, reactor
from twisted.python.log import ILogObserver
@ -20,6 +21,7 @@ import django
django.setup()
from django.conf import settings
from django.db import connection
import evennia
@ -101,10 +103,29 @@ except ImportError:
WEB_PLUGINS_MODULE = None
INFO_DICT["errors"] = (
"WARNING: settings.WEB_PLUGINS_MODULE not found - "
"copy 'evennia/game_template/server/conf/web_plugins.py to mygame/server/conf."
"copy 'evennia/game_template/server/conf/web_plugins.py to "
"mygame/server/conf."
)
_MAINTENANCE_COUNT = 0
def _portal_maintenance():
"""
Repeated maintenance tasks for the portal.
"""
global _MAINTENANCE_COUNT
_MAINTENANCE_COUNT += 1
if _MAINTENANCE_COUNT % (3600 * 7) == 0:
# drop database connection every 7 hrs to avoid default timeouts on MySQL
# (see https://github.com/evennia/evennia/issues/1376)
connection.close()
# -------------------------------------------------------------
# Portal Service object
# -------------------------------------------------------------
@ -143,6 +164,9 @@ class Portal(object):
self.start_time = time.time()
self.maintenance_task = LoopingCall(_portal_maintenance)
self.maintenance_task.start(60, now=True) # call every minute
# in non-interactive portal mode, this gets overwritten by
# cmdline sent by the evennia launcher
self.server_twistd_cmd = self._get_backup_server_twistd_cmd()

View file

@ -249,6 +249,8 @@ class WebSocketClient(WebSocketServerProtocol, _BASE_SESSION_CLASS):
return
else:
return
# just to be sure
text = to_str(text)
flags = self.protocol_flags

View file

@ -6,7 +6,7 @@ Test AMP client
import pickle
from model_mommy import mommy
from unittest import TestCase
from mock import MagicMock, patch
from unittest.mock import MagicMock, patch
from twisted.trial.unittest import TestCase as TwistedTestCase
from evennia.server import amp_client
from evennia.server.portal import amp_server
@ -36,6 +36,7 @@ class _TestAMP(TwistedTestCase):
self.server.sessions[1] = self.session
self.portal = portal.Portal(MagicMock())
self.portal.maintenance_task.stop()
self.portalsession = session.Session()
self.portalsession.sessid = 1
self.portal.sessions[1] = self.portalsession

View file

@ -6,6 +6,7 @@ Runs as part of the Evennia's test suite with 'evennia test evennia"
"""
from django.test.runner import DiscoverRunner
from unittest import mock
class EvenniaTestSuiteRunner(DiscoverRunner):
@ -21,9 +22,16 @@ class EvenniaTestSuiteRunner(DiscoverRunner):
Build a test suite for Evennia. test_labels is a list of apps to test.
If not given, a subset of settings.INSTALLED_APPS will be used.
"""
# the portal looping call starts before the unit-test suite so we
# can't mock it - instead we stop it before starting the test - otherwise
# we'd get unclean reactor errors across test boundaries.
from evennia.server.portal.portal import PORTAL
PORTAL.maintenance_task.stop()
import evennia
evennia._init()
return super(EvenniaTestSuiteRunner, self).build_suite(
test_labels, extra_tests=extra_tests, **kwargs
)