mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-22 10:20:59 +00:00
Merge all log tests into one test module.
This commit is contained in:
parent
d99c94753c
commit
c2d69c5309
@ -1,54 +0,0 @@
|
||||
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
|
||||
|
||||
from allmydata.web.logs import TokenAuthenticatedWebSocketServerProtocol
|
||||
|
||||
|
||||
class TestStreamingLogs(unittest.TestCase):
|
||||
"""
|
||||
Test websocket streaming of logs
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.reactor = MemoryReactorClockResolver()
|
||||
self.pumper = create_pumper()
|
||||
self.agent = create_memory_agent(self.reactor, self.pumper, TokenAuthenticatedWebSocketServerProtocol)
|
||||
return self.pumper.start()
|
||||
|
||||
def tearDown(self):
|
||||
return self.pumper.stop()
|
||||
|
||||
@inlineCallbacks
|
||||
def test_one_log(self):
|
||||
"""
|
||||
write a single Eliot log and see it streamed via websocket
|
||||
"""
|
||||
|
||||
proto = yield self.agent.open(
|
||||
transport_config=u"ws://localhost:1234/ws",
|
||||
options={},
|
||||
)
|
||||
|
||||
messages = []
|
||||
def got_message(msg, is_binary=False):
|
||||
messages.append(json.loads(msg))
|
||||
proto.on("message", got_message)
|
||||
|
||||
@log_call(action_type=u"test:cli:some-exciting-action")
|
||||
def do_a_thing():
|
||||
pass
|
||||
|
||||
do_a_thing()
|
||||
|
||||
proto.transport.loseConnection()
|
||||
yield proto.is_closed
|
||||
|
||||
self.assertEqual(len(messages), 2)
|
||||
self.assertEqual("started", messages[0]["action_status"])
|
||||
self.assertEqual("succeeded", messages[1]["action_status"])
|
@ -1,5 +1,7 @@
|
||||
"""
|
||||
Tests for ``allmydata.web.logs``.
|
||||
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from __future__ import (
|
||||
@ -13,6 +15,15 @@ from future.utils import PY2
|
||||
if PY2:
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||
|
||||
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
|
||||
|
||||
from testtools.matchers import (
|
||||
Equals,
|
||||
)
|
||||
@ -41,6 +52,7 @@ from ..common import (
|
||||
|
||||
from ...web.logs import (
|
||||
create_log_resources,
|
||||
TokenAuthenticatedWebSocketServerProtocol,
|
||||
)
|
||||
|
||||
class StreamingEliotLogsTests(SyncTestCase):
|
||||
@ -61,3 +73,47 @@ class StreamingEliotLogsTests(SyncTestCase):
|
||||
self.client.get(b"http:///v1"),
|
||||
succeeded(has_response_code(Equals(OK))),
|
||||
)
|
||||
|
||||
|
||||
class TestStreamingLogs(unittest.TestCase):
|
||||
"""
|
||||
Test websocket streaming of logs
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.reactor = MemoryReactorClockResolver()
|
||||
self.pumper = create_pumper()
|
||||
self.agent = create_memory_agent(self.reactor, self.pumper, TokenAuthenticatedWebSocketServerProtocol)
|
||||
return self.pumper.start()
|
||||
|
||||
def tearDown(self):
|
||||
return self.pumper.stop()
|
||||
|
||||
@inlineCallbacks
|
||||
def test_one_log(self):
|
||||
"""
|
||||
write a single Eliot log and see it streamed via websocket
|
||||
"""
|
||||
|
||||
proto = yield self.agent.open(
|
||||
transport_config=u"ws://localhost:1234/ws",
|
||||
options={},
|
||||
)
|
||||
|
||||
messages = []
|
||||
def got_message(msg, is_binary=False):
|
||||
messages.append(json.loads(msg))
|
||||
proto.on("message", got_message)
|
||||
|
||||
@log_call(action_type=u"test:cli:some-exciting-action")
|
||||
def do_a_thing():
|
||||
pass
|
||||
|
||||
do_a_thing()
|
||||
|
||||
proto.transport.loseConnection()
|
||||
yield proto.is_closed
|
||||
|
||||
self.assertEqual(len(messages), 2)
|
||||
self.assertEqual("started", messages[0]["action_status"])
|
||||
self.assertEqual("succeeded", messages[1]["action_status"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user