12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
- import asyncio
15
+ import time
16
16
import multiprocessing
17
17
from typing import Dict , Optional
18
18
19
- import pytest
20
19
import xoscar as xo
21
20
21
+ from ...client import Client
22
+ from ...api import restful_api
22
23
from ...core .supervisor import SupervisorActor
23
24
24
25
25
- # test restart supervisor
26
- @pytest .mark .asyncio
27
- async def test_restart_supervisor ():
26
+ def test_restart_supervisor ():
28
27
from ...deploy .supervisor import run_in_subprocess as supervisor_run_in_subprocess
29
28
from ...deploy .worker import main as _start_worker
30
29
@@ -39,50 +38,62 @@ def worker_run_in_subprocess(
39
38
return p
40
39
41
40
# start supervisor
42
- supervisor_address = f"localhost:{ xo .utils .get_next_port ()} "
41
+ web_port , supervisor_port = xo .utils .get_next_port (), xo .utils .get_next_port ()
42
+ supervisor_address = f"127.0.0.1:{ supervisor_port } "
43
43
proc_supervisor = supervisor_run_in_subprocess (supervisor_address )
44
+ rest_api_proc = multiprocessing .Process (
45
+ target = restful_api .run ,
46
+ kwargs = dict (
47
+ supervisor_address = supervisor_address ,
48
+ host = "127.0.0.1" ,
49
+ port = web_port
50
+ )
51
+ )
52
+ rest_api_proc .start ()
44
53
45
- await asyncio .sleep (5 )
54
+ time .sleep (5 )
46
55
47
56
# start worker
48
- worker_run_in_subprocess (
49
- address = f"localhost :{ xo .utils .get_next_port ()} " ,
57
+ proc_worker = worker_run_in_subprocess (
58
+ address = f"127.0.0.1 :{ xo .utils .get_next_port ()} " ,
50
59
supervisor_address = supervisor_address ,
51
60
)
52
61
53
- await asyncio .sleep (10 )
62
+ time .sleep (10 )
54
63
55
- # load model
56
- supervisor_ref = await xo .actor_ref (
57
- supervisor_address , SupervisorActor .default_uid ()
58
- )
64
+ client = Client (f"http://127.0.0.1:{ web_port } " )
59
65
60
- model_uid = "qwen1.5-chat"
61
- await supervisor_ref .launch_builtin_model (
62
- model_uid = model_uid ,
63
- model_name = "qwen1.5-chat" ,
64
- model_size_in_billions = "0_5" ,
65
- quantization = "q4_0" ,
66
- model_engine = "llama.cpp" ,
67
- )
66
+ try :
67
+ model_uid = "qwen1.5-chat"
68
+ client .launch_model (
69
+ model_uid = model_uid ,
70
+ model_name = "qwen1.5-chat" ,
71
+ model_size_in_billions = "0_5" ,
72
+ quantization = "q4_0" ,
73
+ model_engine = "llama.cpp" ,
74
+ )
68
75
69
- # query replica info
70
- model_replica_info = await supervisor_ref .describe_model (model_uid )
76
+ # query replica info
77
+ model_replica_info = client .describe_model (model_uid )
78
+ assert model_replica_info is not None
71
79
72
- # kill supervisor
73
- proc_supervisor .terminate ()
74
- proc_supervisor .join ()
80
+ # kill supervisor
81
+ proc_supervisor .terminate ()
82
+ proc_supervisor .join ()
75
83
76
- # restart supervisor
77
- proc_supervisor = supervisor_run_in_subprocess (supervisor_address )
84
+ # restart supervisor
85
+ supervisor_run_in_subprocess (supervisor_address )
78
86
79
- await asyncio .sleep (5 )
87
+ time .sleep (5 )
80
88
81
- supervisor_ref = await xo . actor_ref (
82
- supervisor_address , SupervisorActor . default_uid ( )
83
- )
89
+ # check replica info
90
+ model_replic_info_check = client . describe_model ( model_uid )
91
+ assert model_replica_info [ "replica" ] == model_replic_info_check [ "replica" ]
84
92
85
- # check replica info
86
- model_replic_info_check = await supervisor_ref .describe_model (model_uid )
93
+ finally :
94
+ client .abort_cluster ()
95
+ proc_supervisor .terminate ()
96
+ proc_worker .terminate ()
97
+ proc_supervisor .join ()
98
+ proc_worker .join ()
87
99
88
- assert model_replica_info ["replica" ] == model_replic_info_check ["replica" ]
0 commit comments