Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,015 changes: 1,015 additions & 0 deletions docs/designs/RFE423-app-cache-key/FS.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion e2e/src/e2e/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"""

from .api import (
TestContext,
TestRequest,
TestResponse,
TestContext,
)

__version__ = "0.4.0"
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/e2e/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
limitations under the License.
"""

from typing import Optional, Dict, Any
from dataclasses import dataclass
from typing import Any, Dict, Optional


@dataclass
Expand Down
10 changes: 5 additions & 5 deletions e2e/src/e2e/basic_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
limitations under the License.
"""

import flamepy
import logging
from typing import Optional

import flamepy

from e2e.api import (
TestRequest,
TestResponse,
TestContext,
ApplicationContextInfo,
SessionContextInfo,
TaskContextInfo,
TestContext,
TestRequest,
TestResponse,
)
from e2e.helpers import (
deserialize_request,
deserialize_common_data,
deserialize_request,
serialize_response,
)

Expand Down
3 changes: 2 additions & 1 deletion e2e/src/e2e/error_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
limitations under the License.
"""

import flamepy
import logging
from typing import Optional

import flamepy

logger = logging.getLogger(__name__)


Expand Down
33 changes: 17 additions & 16 deletions e2e/src/e2e/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
"""

import json
import cloudpickle
from dataclasses import asdict
from typing import Optional, Any
from flamepy import ObjectRef, put_object, get_object
from typing import Optional

import cloudpickle
from flamepy import ObjectRef, get_object, put_object
from flamepy.runner import Runner, RunnerContext, RunnerRequest, SessionContext
from flamepy.util import short_name
from flamepy.runner import RunnerContext, RunnerRequest, Runner, SessionContext

from e2e.api import (
ApplicationContextInfo,
SessionContextInfo,
TaskContextInfo,
TestContext,
TestRequest,
TestResponse,
TestContext,
TaskContextInfo,
SessionContextInfo,
ApplicationContextInfo,
)


Expand Down Expand Up @@ -107,10 +108,10 @@ def serialize_runner_context(runner_context: RunnerContext, app_name: str) -> by
"""
# Serialize the context using cloudpickle
serialized_ctx = cloudpickle.dumps(runner_context, protocol=cloudpickle.DEFAULT_PROTOCOL)
# Generate a temporary session_id for caching (will be regenerated by create_session if needed)
temp_session_id = short_name(app_name)
# Generate key prefix in <app>/<session> format for caching
key_prefix = f"{app_name}/{short_name(app_name)}"
# Put in cache to get ObjectRef
object_ref = put_object(temp_session_id, serialized_ctx)
object_ref = put_object(key_prefix, serialized_ctx)
# Encode ObjectRef to bytes for core API
return object_ref.encode()

Expand Down Expand Up @@ -149,8 +150,8 @@ def serialize_common_data(common_data: Optional[TestContext], app_name: str) ->
# Serialize with JSON
serialized_ctx = json.dumps(asdict(common_data)).encode("utf-8")
# Put in cache to get ObjectRef
temp_session_id = short_name(app_name)
object_ref = put_object(temp_session_id, serialized_ctx)
key_prefix = f"{app_name}/{short_name(app_name)}"
object_ref = put_object(key_prefix, serialized_ctx)
# Encode ObjectRef to bytes for core API
return object_ref.encode()

Expand Down Expand Up @@ -302,7 +303,7 @@ def compute_recursive(self, depth: int) -> int:
logger.info(f"[RecursiveService] session_context: session_id={self._session_context.session_id}, app_name={self._session_context.application_name}")

if depth <= 0:
logger.info(f"[RecursiveService] Base case reached, returning 1")
logger.info("[RecursiveService] Base case reached, returning 1")
return 1

try:
Expand All @@ -316,14 +317,14 @@ def compute_recursive(self, depth: int) -> int:
# Create service using Runner.service() with self
# This reuses the existing session via _session_context
# Use autoscale=True to allow multiple executors for recursive calls
logger.info(f"[RecursiveService] Creating inner service with self")
logger.info("[RecursiveService] Creating inner service with self")
inner_service = inner_runner.service(self, autoscale=True)
logger.info(f"[RecursiveService] Inner service created, session_id={inner_service._session.id}")

# Call the inner service recursively
logger.info(f"[RecursiveService] Calling compute_recursive({depth - 1}) on inner service")
result = inner_service.compute_recursive(depth - 1)
logger.info(f"[RecursiveService] Got result future, calling get()")
logger.info("[RecursiveService] Got result future, calling get()")
inner_value = result.get()
logger.info(f"[RecursiveService] Inner value = {inner_value}")

Expand Down
2 changes: 1 addition & 1 deletion e2e/src/e2e/instance_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from flamepy import agent

from e2e.api import TestRequest, TestResponse, TestContext
from e2e.api import TestContext, TestRequest, TestResponse

instance = agent.FlameInstance()

Expand Down
11 changes: 5 additions & 6 deletions e2e/tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
limitations under the License.
"""

import pytest
import flamepy
from flamepy import SessionState, TaskState, FlameError, FlameErrorCode, TaskInformer
import pytest
from flamepy import SessionState
from flamepy.agent import Agent
from e2e.api import TestRequest, TestResponse, TestContext

from e2e.api import TestContext, TestRequest
from tests.utils import random_string
import threading
from concurrent.futures import wait

FLM_TEST_APP = "flme2e"

Expand All @@ -43,7 +42,7 @@ def setup_test_env():
for sess in sessions:
try:
flamepy.close_session(sess.id)
except:
except Exception:
pass

flamepy.unregister_application(FLM_TEST_APP)
Expand Down
1 change: 0 additions & 1 deletion e2e/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
limitations under the License.
"""

import pytest
import flamepy


Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def setup_test_env():
for sess in sessions:
try:
flamepy.close_session(sess.id)
except:
except Exception:
pass

flamepy.unregister_application(FLM_TEST_SVC_APP)
Expand Down
Loading
Loading