Skip to content
This repository was archived by the owner on Oct 21, 2025. It is now read-only.
Open
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
41 changes: 41 additions & 0 deletions tests/integration/integration_test_get_cluster_instance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import asyncio

from fbpcp.intern.service.container_aws_fb import FBAWSContainerService

from measurement.private_measurement.pcp.pce.scripts.pce_service_client import (
PCEServiceClient,
)

ACCOUNT = "482880953677"
TEST_PARTNER_ID = "pce-monitor-test"


async def test_get_cluster_details() -> None:
client = PCEServiceClient("STAGING")
pce_instances = await client.get_pce_for_partner(TEST_PARTNER_ID)
if not pce_instances:
raise Exception("Test not setup correctly, no pce instance")
instance = pce_instances[0]
container_svc = FBAWSContainerService(
region=instance.metadata.cloud_region,
cluster=instance.pce.cluster_name,
subnets=list(instance.pce.subnet_ids),
account=ACCOUNT,
)
cmd = ["echo hello"] * 5
container_svc.create_instances(instance.pce.container_definition_id, cmd)

cluster_instance = container_svc.get_cluster_instance()
print(
f"cluster-name: {cluster_instance.cluster_name}, pending tasks:{cluster_instance.pending_tasks}, running tasks: {cluster_instance.running_tasks}, status: {cluster_instance.status}"
)


if __name__ == "__main__":
asyncio.run(test_get_cluster_details())
29 changes: 28 additions & 1 deletion tests/service/test_container_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from unittest.mock import call, MagicMock, patch
from uuid import uuid4

from fbpcp.entity.cluster_instance import Cluster
from fbpcp.entity.cluster_instance import Cluster, ClusterStatus
from fbpcp.entity.container_instance import ContainerInstance, ContainerInstanceStatus
from fbpcp.error.pcp import PcpError
from fbpcp.service.container_aws import AWS_API_INPUT_SIZE_LIMIT, AWSContainerService
Expand Down Expand Up @@ -271,3 +271,30 @@ def test_auth_keys(self):
}

self.assertEqual(container_aws.ecs_gateway.config, expected_config)

def test_get_cluster_instance(self) -> None:
# Arrange
test_cluster_arn = "test_cluster_arn"
test_cluster_name = TEST_CLUSTER
test_pending_tasks_account = 2
test_running_tasks_account = 3
test_status = ClusterStatus.ACTIVE
self.container_svc.ecs_gateway.describe_cluster = MagicMock(
return_value=Cluster(
cluster_arn=test_cluster_arn,
cluster_name=test_cluster_name,
pending_tasks=test_pending_tasks_account,
running_tasks=test_running_tasks_account,
status=test_status,
)
)
# Act
cluster_instant = self.container_svc.ecs_gateway.describe_cluster(
test_cluster_name
)
# Assert
self.assertEqual(cluster_instant.cluster_arn, test_cluster_arn)
self.assertEqual(cluster_instant.cluster_name, test_cluster_name)
self.assertEqual(cluster_instant.pending_tasks, test_pending_tasks_account)
self.assertEqual(cluster_instant.running_tasks, test_running_tasks_account)
self.assertEqual(cluster_instant.status, test_status)