mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 05:28:04 +00:00
Refactored test_logs to be consistent with base testcases
Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
This commit is contained in:
parent
580af66b69
commit
492bcbbd12
1
newsfragments/3758.other
Normal file
1
newsfragments/3758.other
Normal file
@ -0,0 +1 @@
|
||||
Refactored test_logs, test_grid and test_root in web tests to use custom base test cases
|
@ -17,10 +17,8 @@ if PY2:
|
||||
|
||||
import json
|
||||
|
||||
from twisted.trial import unittest
|
||||
from twisted.internet.defer import inlineCallbacks
|
||||
|
||||
from eliot import log_call
|
||||
|
||||
from autobahn.twisted.testing import create_memory_agent, MemoryReactorClockResolver, create_pumper
|
||||
|
||||
@ -48,6 +46,7 @@ from .matchers import (
|
||||
|
||||
from ..common import (
|
||||
SyncTestCase,
|
||||
AsyncTestCase,
|
||||
)
|
||||
|
||||
from ...web.logs import (
|
||||
@ -55,6 +54,10 @@ from ...web.logs import (
|
||||
TokenAuthenticatedWebSocketServerProtocol,
|
||||
)
|
||||
|
||||
from ...util.eliotutil import (
|
||||
log_call_deferred
|
||||
)
|
||||
|
||||
class StreamingEliotLogsTests(SyncTestCase):
|
||||
"""
|
||||
Tests for the log streaming resources created by ``create_log_resources``.
|
||||
@ -75,18 +78,20 @@ class StreamingEliotLogsTests(SyncTestCase):
|
||||
)
|
||||
|
||||
|
||||
class TestStreamingLogs(unittest.TestCase):
|
||||
class TestStreamingLogs(AsyncTestCase):
|
||||
"""
|
||||
Test websocket streaming of logs
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestStreamingLogs, self).setUp()
|
||||
self.reactor = MemoryReactorClockResolver()
|
||||
self.pumper = create_pumper()
|
||||
self.agent = create_memory_agent(self.reactor, self.pumper, TokenAuthenticatedWebSocketServerProtocol)
|
||||
return self.pumper.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestStreamingLogs, self).tearDown()
|
||||
return self.pumper.stop()
|
||||
|
||||
@inlineCallbacks
|
||||
@ -105,7 +110,7 @@ class TestStreamingLogs(unittest.TestCase):
|
||||
messages.append(json.loads(msg))
|
||||
proto.on("message", got_message)
|
||||
|
||||
@log_call(action_type=u"test:cli:some-exciting-action")
|
||||
@log_call_deferred(action_type=u"test:cli:some-exciting-action")
|
||||
def do_a_thing(arguments):
|
||||
pass
|
||||
|
||||
@ -114,10 +119,10 @@ class TestStreamingLogs(unittest.TestCase):
|
||||
proto.transport.loseConnection()
|
||||
yield proto.is_closed
|
||||
|
||||
self.assertEqual(len(messages), 2)
|
||||
self.assertEqual(messages[0]["action_type"], "test:cli:some-exciting-action")
|
||||
self.assertEqual(messages[0]["arguments"],
|
||||
["hello", "good-\\xff-day", 123, {"a": 35}, [None]])
|
||||
self.assertEqual(messages[1]["action_type"], "test:cli:some-exciting-action")
|
||||
self.assertEqual("started", messages[0]["action_status"])
|
||||
self.assertEqual("succeeded", messages[1]["action_status"])
|
||||
self.assertThat(len(messages), Equals(3))
|
||||
self.assertThat(messages[0]["action_type"], Equals("test:cli:some-exciting-action"))
|
||||
self.assertThat(messages[0]["arguments"],
|
||||
Equals(["hello", "good-\\xff-day", 123, {"a": 35}, [None]]))
|
||||
self.assertThat(messages[1]["action_type"], Equals("test:cli:some-exciting-action"))
|
||||
self.assertThat("started", Equals(messages[0]["action_status"]))
|
||||
self.assertThat("succeeded", Equals(messages[1]["action_status"]))
|
||||
|
@ -87,7 +87,11 @@ from twisted.internet.defer import (
|
||||
)
|
||||
from twisted.application.service import Service
|
||||
|
||||
from .jsonbytes import AnyBytesJSONEncoder
|
||||
from .jsonbytes import (
|
||||
AnyBytesJSONEncoder,
|
||||
bytes_to_unicode
|
||||
)
|
||||
|
||||
|
||||
|
||||
def validateInstanceOf(t):
|
||||
@ -320,7 +324,8 @@ def log_call_deferred(action_type):
|
||||
def logged_f(*a, **kw):
|
||||
# Use the action's context method to avoid ending the action when
|
||||
# the `with` block ends.
|
||||
with start_action(action_type=action_type).context():
|
||||
args = bytes_to_unicode(True, kw['arguments'])
|
||||
with start_action(action_type=action_type, arguments=args).context():
|
||||
# Use addActionFinish so that the action finishes when the
|
||||
# Deferred fires.
|
||||
d = maybeDeferred(f, *a, **kw)
|
||||
|
Loading…
Reference in New Issue
Block a user