2022-12-11 14:02:55 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import trio
|
2022-12-11 16:06:07 +00:00
|
|
|
import pynng
|
|
|
|
import pytest
|
2022-12-11 14:02:55 +00:00
|
|
|
import trio_asyncio
|
|
|
|
|
2022-12-17 14:39:42 +00:00
|
|
|
from skynet.brain import run_skynet
|
|
|
|
from skynet.structs import *
|
|
|
|
from skynet.frontend import open_skynet_rpc
|
2022-12-11 14:02:55 +00:00
|
|
|
|
|
|
|
|
2022-12-19 15:36:02 +00:00
|
|
|
async def test_skynet(skynet_running):
|
|
|
|
...
|
|
|
|
|
|
|
|
|
2022-12-11 16:06:07 +00:00
|
|
|
async def test_skynet_attempt_insecure(skynet_running):
|
|
|
|
with pytest.raises(pynng.exceptions.NNGException) as e:
|
2022-12-19 15:36:02 +00:00
|
|
|
async with open_skynet_rpc('bad-actor'):
|
|
|
|
...
|
2022-12-11 16:06:07 +00:00
|
|
|
|
|
|
|
assert str(e.value) == 'Connection shutdown'
|
|
|
|
|
|
|
|
|
2022-12-11 14:02:55 +00:00
|
|
|
async def test_skynet_dgpu_connection_simple(skynet_running):
|
2022-12-11 16:06:07 +00:00
|
|
|
async with open_skynet_rpc(
|
2022-12-19 15:36:02 +00:00
|
|
|
'dgpu-0',
|
2022-12-11 16:06:07 +00:00
|
|
|
security=True,
|
|
|
|
cert_name='whitelist/testing',
|
|
|
|
key_name='testing'
|
|
|
|
) as rpc_call:
|
2022-12-11 14:02:55 +00:00
|
|
|
# check 0 nodes are connected
|
2022-12-19 15:36:02 +00:00
|
|
|
res = await rpc_call('dgpu_workers')
|
2022-12-11 14:02:55 +00:00
|
|
|
assert 'ok' in res.result
|
|
|
|
assert res.result['ok'] == 0
|
|
|
|
|
|
|
|
# check next worker is None
|
2022-12-19 15:36:02 +00:00
|
|
|
res = await rpc_call('dgpu_next')
|
2022-12-11 14:02:55 +00:00
|
|
|
assert 'ok' in res.result
|
|
|
|
assert res.result['ok'] == None
|
|
|
|
|
|
|
|
# connect 1 dgpu
|
2022-12-19 15:36:02 +00:00
|
|
|
res = await rpc_call('dgpu_online')
|
2022-12-11 14:02:55 +00:00
|
|
|
assert 'ok' in res.result
|
|
|
|
|
|
|
|
# check 1 node is connected
|
2022-12-19 15:36:02 +00:00
|
|
|
res = await rpc_call('dgpu_workers')
|
2022-12-11 14:02:55 +00:00
|
|
|
assert 'ok' in res.result
|
|
|
|
assert res.result['ok'] == 1
|
|
|
|
|
|
|
|
# check next worker is 0
|
2022-12-19 15:36:02 +00:00
|
|
|
res = await rpc_call('dgpu_next')
|
2022-12-11 14:02:55 +00:00
|
|
|
assert 'ok' in res.result
|
|
|
|
assert res.result['ok'] == 0
|
|
|
|
|
|
|
|
# disconnect 1 dgpu
|
2022-12-19 15:36:02 +00:00
|
|
|
res = await rpc_call('dgpu_offline')
|
2022-12-11 14:02:55 +00:00
|
|
|
assert 'ok' in res.result
|
|
|
|
|
|
|
|
# check 0 nodes are connected
|
2022-12-19 15:36:02 +00:00
|
|
|
res = await rpc_call('dgpu_workers')
|
2022-12-11 14:02:55 +00:00
|
|
|
assert 'ok' in res.result
|
|
|
|
assert res.result['ok'] == 0
|
|
|
|
|
|
|
|
# check next worker is None
|
2022-12-19 15:36:02 +00:00
|
|
|
res = await rpc_call('dgpu_next')
|
2022-12-11 14:02:55 +00:00
|
|
|
assert 'ok' in res.result
|
|
|
|
assert res.result['ok'] == None
|