mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix netapi tests
This commit is contained in:
parent
5ac48c5161
commit
e8c016419b
7 changed files with 16 additions and 17 deletions
|
@ -558,8 +558,6 @@ class AsyncAuth:
|
|||
self._crypticle = Crypticle(self.opts, creds["aes"])
|
||||
self._authenticate_future = tornado.concurrent.Future()
|
||||
self._authenticate_future.set_result(True)
|
||||
#else:
|
||||
# self.authenticate()
|
||||
|
||||
def __deepcopy__(self, memo):
|
||||
cls = self.__class__
|
||||
|
|
|
@ -58,7 +58,8 @@ class SyncWrapper:
|
|||
close_methods=None,
|
||||
loop_kwarg=None,
|
||||
):
|
||||
self.io_loop = tornado.ioloop.IOLoop()
|
||||
self.asyncio_loop = asyncio.new_event_loop()
|
||||
self.io_loop = tornado.ioloop.IOLoop(asyncio_loop=self.asyncio_loop)
|
||||
if args is None:
|
||||
args = []
|
||||
if kwargs is None:
|
||||
|
@ -124,7 +125,7 @@ class SyncWrapper:
|
|||
results = []
|
||||
thread = threading.Thread(
|
||||
target=self._target,
|
||||
args=(key, args, kwargs, results, self.io_loop),
|
||||
args=(key, args, kwargs, results, self.asyncio_loop),
|
||||
)
|
||||
thread.start()
|
||||
thread.join()
|
||||
|
@ -136,7 +137,9 @@ class SyncWrapper:
|
|||
|
||||
return wrap
|
||||
|
||||
def _target(self, key, args, kwargs, results, io_loop):
|
||||
def _target(self, key, args, kwargs, results, asyncio_loop):
|
||||
asyncio.set_event_loop(asyncio_loop)
|
||||
io_loop = tornado.ioloop.IOLoop.current()
|
||||
try:
|
||||
result = io_loop.run_sync(lambda: getattr(self.obj, key)(*args, **kwargs))
|
||||
results.append(True)
|
||||
|
|
|
@ -604,11 +604,6 @@ def pytest_pyfunc_call(pyfuncitem):
|
|||
loop = funcargs["io_loop"]
|
||||
except KeyError:
|
||||
loop = tornado.ioloop.IOLoop.current()
|
||||
if loop.closed():
|
||||
log.warning("IOLoop found to be closed when starting test")
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
loop = tornado.ioloop.IOLoop.current()
|
||||
|
||||
__tracebackhide__ = True
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import salt.utils.stringutils
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.skip_on_spawning_platform(
|
||||
reason="These tests are currently broken on spawning platforms. Need to be rewritten.",
|
||||
|
@ -176,7 +175,9 @@ def test_pub_server_channel(
|
|||
assert not bool(os.lstat(p).st_mode & stat.S_IRGRP)
|
||||
assert not bool(os.lstat(p).st_mode & stat.S_IROTH)
|
||||
|
||||
pub_channel = salt.channel.client.AsyncPubChannel.factory(minion_config, io_loop=io_loop)
|
||||
pub_channel = salt.channel.client.AsyncPubChannel.factory(
|
||||
minion_config, io_loop=io_loop
|
||||
)
|
||||
received = []
|
||||
|
||||
try:
|
||||
|
|
|
@ -28,8 +28,9 @@ def app(client_config, load_auth):
|
|||
)
|
||||
|
||||
|
||||
# The order of these fixtures matter, app before io_loop
|
||||
@pytest.fixture
|
||||
def http_server(io_loop, app, netapi_port):
|
||||
def http_server(app, netapi_port, io_loop):
|
||||
with netapi.TestsTornadoHttpServer(
|
||||
io_loop=io_loop, app=app, port=netapi_port
|
||||
) as server:
|
||||
|
|
|
@ -277,8 +277,9 @@ def client_config(client_config, external_auth):
|
|||
return client_config
|
||||
|
||||
|
||||
# The order of these fixtures matter, io_loop must come after app
|
||||
@pytest.fixture
|
||||
def http_server(io_loop, app, netapi_port, content_type_map):
|
||||
def http_server(app, netapi_port, content_type_map, io_loop):
|
||||
with netapi.TestsTornadoHttpServer(
|
||||
io_loop=io_loop,
|
||||
app=app,
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import functools
|
||||
import os
|
||||
import socket
|
||||
|
||||
|
@ -242,6 +241,7 @@ def test_tcp_pub_server_channel_publish_filtering_str_list(temp_salt_master):
|
|||
@pytest.fixture(scope="function")
|
||||
def salt_message_client():
|
||||
io_loop_mock = MagicMock(spec=tornado.ioloop.IOLoop)
|
||||
io_loop_mock.asyncio_loop = None
|
||||
io_loop_mock.call_later.side_effect = lambda *args, **kwargs: (args, kwargs)
|
||||
|
||||
client = salt.transport.tcp.MessageClient(
|
||||
|
@ -453,7 +453,7 @@ def test_presence_events_callback_passed(temp_salt_master, salt_message_client):
|
|||
)
|
||||
|
||||
|
||||
def test_presence_removed_on_stream_closed():
|
||||
async def test_presence_removed_on_stream_closed():
|
||||
opts = {"presence_events": True}
|
||||
|
||||
io_loop_mock = MagicMock(spec=tornado.ioloop.IOLoop)
|
||||
|
@ -478,6 +478,6 @@ def test_presence_removed_on_stream_closed():
|
|||
"tornado.iostream.BaseIOStream.write",
|
||||
side_effect=tornado.iostream.StreamClosedError(),
|
||||
):
|
||||
io_loop.run_sync(functools.partial(server.publish_payload, package, None))
|
||||
await server.publish_payload(package, None)
|
||||
|
||||
server.remove_presence_callback.assert_called_with(client)
|
||||
|
|
Loading…
Add table
Reference in a new issue