Skip to content

Commit

Permalink
fix mega uts.
Browse files Browse the repository at this point in the history
  • Loading branch information
lkk12014402 committed Dec 11, 2024
1 parent 16eeaef commit ca35421
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
6 changes: 4 additions & 2 deletions tests/cores/mega/test_base_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import time
import unittest

import multiprocessing
import requests

from comps import (
Expand Down Expand Up @@ -34,13 +34,15 @@ async def s1_add(request: TextDoc) -> TextDoc:
class TestBaseStatistics(unittest.IsolatedAsyncioTestCase):
def setUp(self):
self.s1 = opea_microservices["s1"]
self.s1.start()
self.process1 = multiprocessing.Process(target=self.s1.start, daemon=False, name="s1")
self.process1.start()

self.service_builder = ServiceOrchestrator()
self.service_builder.add(opea_microservices["s1"])

def tearDown(self):
self.s1.stop()
self.process1.terminate()

async def test_base_statistics(self):
for _ in range(2):
Expand Down
5 changes: 4 additions & 1 deletion tests/cores/mega/test_dynamic_batching.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import asyncio
import unittest
from enum import Enum
import multiprocessing

import aiohttp

Expand Down Expand Up @@ -67,10 +68,12 @@ async def fetch(session, url, data):

class TestMicroService(unittest.IsolatedAsyncioTestCase):
def setUp(self):
opea_microservices["s1"].start()
self.process1 = multiprocessing.Process(target=opea_microservices["s1"].start, daemon=False, name="s1")
self.process1.start()

def tearDown(self):
opea_microservices["s1"].stop()
self.process1.terminate()

async def test_dynamic_batching(self):
url1 = "http://localhost:8080/v1/add1"
Expand Down
12 changes: 1 addition & 11 deletions tests/cores/mega/test_handle_message.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import sys

sys.path.append("/lkk/move_gateway/GenAIComps/")

import json
import unittest
from typing import Union
Expand All @@ -18,9 +14,7 @@ def test_handle_message(self):
messages = [
{"role": "user", "content": "opea project! "},
]
print(handle_message(messages))
prompt = handle_message(messages)
print(prompt)
self.assertEqual(prompt, "user: opea project! \n")

def test_handle_message_with_system_prompt(self):
Expand All @@ -29,7 +23,6 @@ def test_handle_message_with_system_prompt(self):
{"role": "user", "content": "opea project! "},
]
prompt = handle_message(messages)
print(prompt)
self.assertEqual(prompt, "System Prompt\nuser: opea project! \n")

def test_handle_message_with_image(self):
Expand All @@ -46,10 +39,7 @@ def test_handle_message_with_image(self):
},
]
prompt, image = handle_message(messages)
print(prompt)


if __name__ == "__main__":
# unittest.main()
t = TestHandleMessage()
t.test_handle_message_with_image()
unittest.main()
6 changes: 4 additions & 2 deletions tests/cores/mega/test_hybrid_service_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import json
import unittest

import multiprocessing
from comps import MicroService, ServiceOrchestrator, TextDoc, opea_microservices, register_microservice


Expand All @@ -19,12 +19,14 @@ async def s1_add(request: TextDoc) -> TextDoc:
class TestServiceOrchestrator(unittest.TestCase):
def setUp(self):
self.s1 = opea_microservices["s1"]
self.s1.start()
self.process1 = multiprocessing.Process(target=self.s1.start, daemon=False, name="s1")
self.process1.start()

self.service_builder = ServiceOrchestrator()

def tearDown(self):
self.s1.stop()
self.process1.terminate()

def test_add_remote_service(self):
s2 = MicroService(name="s2", host="fakehost", port=8008, endpoint="/v1/add", use_remote_service=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import json
import unittest

import multiprocessing
from comps import ServiceOrchestratorWithYaml, TextDoc, opea_microservices, register_microservice


Expand All @@ -19,10 +19,12 @@ async def s1_add(request: TextDoc) -> TextDoc:
class TestYAMLOrchestrator(unittest.TestCase):
def setUp(self) -> None:
self.s1 = opea_microservices["s1"]
self.s1.start()
self.process1 = multiprocessing.Process(target=self.s1.start, daemon=False, name="s1")
self.process1.start()

def tearDown(self):
self.s1.stop()
self.process1.terminate()

def test_add_remote_service(self):
service_builder = ServiceOrchestratorWithYaml(yaml_file_path="megaservice_hybrid.yaml")
Expand Down
6 changes: 5 additions & 1 deletion tests/cores/mega/test_microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import json
import unittest
import multiprocessing

from fastapi.testclient import TestClient

Expand All @@ -22,10 +23,13 @@ class TestMicroService(unittest.TestCase):
def setUp(self):
self.client = TestClient(opea_microservices["s1"].app)

opea_microservices["s1"].start()
self.process1 = multiprocessing.Process(target=opea_microservices["s1"].start, daemon=False, name="s1")

self.process1.start()

def tearDown(self):
opea_microservices["s1"].stop()
self.process1.terminate()

def test_add_route(self):
response = self.client.post("/v1/add", json={"text": "Hello, "})
Expand Down
6 changes: 4 additions & 2 deletions tests/cores/mega/test_service_orchestrator_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

import unittest

import multiprocessing
from comps import ServiceOrchestrator, opea_microservices, register_microservice
from comps.cores.proto.api_protocol import ChatCompletionRequest

Expand All @@ -16,14 +16,16 @@ async def s1_add(request: ChatCompletionRequest) -> ChatCompletionRequest:
class TestServiceOrchestratorProtocol(unittest.IsolatedAsyncioTestCase):
def setUp(self):
self.s1 = opea_microservices["s1"]
self.s1.start()
self.process1 = multiprocessing.Process(target=self.s1.start, daemon=False, name="s1")
self.process1.start()

self.service_builder = ServiceOrchestrator()

self.service_builder.add(opea_microservices["s1"])

def tearDown(self):
self.s1.stop()
self.process1.terminate()

async def test_schedule(self):
input_data = ChatCompletionRequest(messages=[{"role": "user", "content": "What's up man?"}], seed=None)
Expand Down

0 comments on commit ca35421

Please sign in to comment.