diff --git a/stack/cloud_function_scene_relevancy.py b/stack/cloud_function_scene_relevancy.py index 31526bc0..b8a1aa69 100644 --- a/stack/cloud_function_scene_relevancy.py +++ b/stack/cloud_function_scene_relevancy.py @@ -21,7 +21,7 @@ construct_name("queue-cr-orchestrator"), location=pulumi.Config("gcp").require("region"), rate_limits=cloudtasks.QueueRateLimitsArgs( - max_concurrent_dispatches=50, + max_concurrent_dispatches=40, max_dispatches_per_second=1, ), retry_config=cloudtasks.QueueRetryConfigArgs( diff --git a/test/test_cerulean_cloud/test_cloud_function_scene_relevancy.py b/test/test_cerulean_cloud/test_cloud_function_scene_relevancy.py index 5c9149a1..c48ecbf7 100644 --- a/test/test_cerulean_cloud/test_cloud_function_scene_relevancy.py +++ b/test/test_cerulean_cloud/test_cloud_function_scene_relevancy.py @@ -32,3 +32,117 @@ def test_make_logs(): "timeRange=2022-07-15T11:13:12.183229Z%2F2022-07-15T11:15:12.183229Z;" "cursorTimestamp=2022-07-15T11:13:12.183229Z?project=cerulean-338116" ) + + +def test_handle_notification_filters(): + ocean_poly = load_ocean_poly( + "cerulean_cloud/cloud_function_scene_relevancy/OceanGeoJSON_lowres.geojson" + ) + + # Valid scene/polygon (should produce a non-empty result if it normally does) + valid_scene_id = ( + "S1A_IW_GRDH_1SDV_20240730T001806_20240730T001831_054983_06B2B8_3CE1" + ) + valid_event = { + "Records": [ + { + "Sns": { + "Message": json.dumps( + { + "id": valid_scene_id, + "footprint": { + "type": "Polygon", + "coordinates": [ + [ + [ + [0.0, 0.0], + [0.0, 1.0], + [1.0, 1.0], + [1.0, 0.0], + [0.0, 0.0], + ] + ] + ], + }, + } + ) + } + } + ] + } + valid_res = handle_notification(valid_event, ocean_poly=ocean_poly) + # Depending on logic, this should be non-empty if it meets the criteria for relevancy + # If the function currently filters on ocean/intersection, adjust the polygon or expectations accordingly. + # For now we assume it should return something. If it doesn't, adjust your logic or polygon. + assert len(valid_res) > 0, "Expected at least one result for a valid scene/polygon" + + # Invalid scene IDs (should all be rejected) + invalid_scene_ids = [ + "S1A_S3_GRDH_1SDV_20", + "S1A_IW_GRDM_1SDV_20", + "S1A_IW_GRDH_1SDH_20", + ] + + for scene_id in invalid_scene_ids: + invalid_event = { + "Records": [ + { + "Sns": { + "Message": json.dumps( + { + "id": scene_id, + "footprint": { + "type": "Polygon", + "coordinates": [ + [ + [ + [0.0, 0.0], + [0.0, 1.0], + [1.0, 1.0], + [1.0, 0.0], + [0.0, 0.0], + ] + ] + ], + }, + } + ) + } + } + ] + } + invalid_res = handle_notification(invalid_event, ocean_poly=ocean_poly) + assert ( + len(invalid_res) == 0 + ), f"Expected no results for invalid scene_id {scene_id}" + + # Invalid polygon (should be rejected) + invalid_polygon_event = { + "Records": [ + { + "Sns": { + "Message": json.dumps( + { + "id": valid_scene_id, + "footprint": { + "type": "Polygon", + "coordinates": [ + [ + [ + [10.0, 10.0], + [10.0, 11.0], + [11.0, 11.0], + [11.0, 10.0], + [10.0, 10.0], + ] + ] + ], + }, + } + ) + } + } + ] + } + invalid_poly_res = handle_notification(invalid_polygon_event, ocean_poly=ocean_poly) + assert len(invalid_poly_res) == 0, "Expected no results for invalid polygon"