Skip to content

Commit 3801710

Browse files
committed
fix(testing-sdk): update WaitDetails to use scheduled_end_timestamp and use datetime
1 parent afb374e commit 3801710

File tree

14 files changed

+165
-148
lines changed

14 files changed

+165
-148
lines changed

.github/workflows/deploy-examples.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ jobs:
9696
echo "QUALIFIED_FUNCTION_NAME=$QUALIFIED_FUNCTION_NAME" >> $GITHUB_ENV
9797
echo "VERSION=$VERSION" >> $GITHUB_ENV
9898
99+
# Wait for function to be ready
100+
echo "Waiting for function to be active..."
101+
aws lambda wait function-active --function-name "$QUALIFIED_FUNCTION_NAME" --endpoint-url "$LAMBDA_ENDPOINT" --region "${{ env.AWS_REGION }}"
102+
99103
- name: Invoke Lambda function - ${{ matrix.example.name }}
100104
env:
101105
LAMBDA_ENDPOINT: ${{ secrets.LAMBDA_ENDPOINT_BETA }}

examples/test/test_wait.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ def test_wait():
2121
wait_ops = [op for op in result.operations if op.operation_type.value == "WAIT"]
2222
assert len(wait_ops) == 1
2323
wait_op = wait_ops[0]
24-
assert wait_op.scheduled_timestamp is not None
24+
assert wait_op.scheduled_end_timestamp is not None

src/aws_durable_execution_sdk_python_testing/checkpoint/processors/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ def _create_wait_details(
122122
"""Create WaitDetails from OperationUpdate."""
123123
if update.operation_type == OperationType.WAIT and update.wait_options:
124124
if current_operation and current_operation.wait_details:
125-
scheduled_timestamp = current_operation.wait_details.scheduled_timestamp
125+
scheduled_end_timestamp = (
126+
current_operation.wait_details.scheduled_end_timestamp
127+
)
126128
else:
127-
scheduled_timestamp = datetime.datetime.now(
129+
scheduled_end_timestamp = datetime.datetime.now(
128130
tz=datetime.UTC
129131
) + timedelta(seconds=update.wait_options.wait_seconds)
130-
return WaitDetails(scheduled_timestamp=scheduled_timestamp)
132+
return WaitDetails(scheduled_end_timestamp=scheduled_end_timestamp)
131133
return None
132134

133135
def _translate_update_to_operation(

src/aws_durable_execution_sdk_python_testing/checkpoint/processors/wait.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ def process(
4141
wait_seconds = (
4242
update.wait_options.wait_seconds if update.wait_options else 0
4343
)
44-
scheduled_timestamp = datetime.now(UTC) + timedelta(
44+
scheduled_end_timestamp = datetime.now(UTC) + timedelta(
4545
seconds=wait_seconds
4646
)
4747

4848
# Create WaitDetails with scheduled timestamp
49-
wait_details = WaitDetails(scheduled_timestamp=scheduled_timestamp)
49+
wait_details = WaitDetails(
50+
scheduled_end_timestamp=scheduled_end_timestamp
51+
)
5052

5153
# Create new operation with wait details
5254
wait_operation = Operation(

src/aws_durable_execution_sdk_python_testing/executor.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,15 @@ def get_execution_details(self, execution_arn: str) -> GetDurableExecutionRespon
142142
durable_execution_name=execution.start_input.execution_name,
143143
function_arn=f"arn:aws:lambda:us-east-1:123456789012:function:{execution.start_input.function_name}",
144144
status=status,
145-
start_timestamp=execution_op.start_timestamp.timestamp()
145+
start_timestamp=execution_op.start_timestamp
146146
if execution_op.start_timestamp
147-
else datetime.now(UTC).timestamp(),
147+
else datetime.now(UTC),
148148
input_payload=execution_op.execution_details.input_payload
149149
if execution_op.execution_details
150150
else None,
151151
result=result,
152152
error=error,
153-
end_timestamp=execution_op.end_timestamp.timestamp()
154-
if execution_op.end_timestamp
155-
else None,
153+
end_timestamp=execution_op.end_timestamp,
156154
version="1.0",
157155
)
158156

@@ -223,12 +221,10 @@ def list_executions(
223221
durable_execution_name=execution.start_input.execution_name,
224222
function_arn=f"arn:aws:lambda:us-east-1:123456789012:function:{execution.start_input.function_name}",
225223
status=execution_status,
226-
start_timestamp=execution_op.start_timestamp.timestamp()
224+
start_timestamp=execution_op.start_timestamp
227225
if execution_op.start_timestamp
228-
else datetime.now(UTC).timestamp(),
229-
end_timestamp=execution_op.end_timestamp.timestamp()
230-
if execution_op.end_timestamp
231-
else None,
226+
else datetime.now(UTC),
227+
end_timestamp=execution_op.end_timestamp,
232228
)
233229
filtered_executions.append(execution_summary)
234230

@@ -333,7 +329,7 @@ def stop_execution(
333329
# Stop the execution
334330
self.fail_execution(execution_arn, stop_error)
335331

336-
return StopDurableExecutionResponse(end_timestamp=datetime.now(UTC).timestamp())
332+
return StopDurableExecutionResponse(stop_timestamp=datetime.now(UTC))
337333

338334
def get_execution_state(
339335
self,

src/aws_durable_execution_sdk_python_testing/model.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
from __future__ import annotations
44

55
from dataclasses import dataclass
6-
from typing import Any
6+
from typing import TYPE_CHECKING, Any
7+
8+
9+
if TYPE_CHECKING:
10+
import datetime
711

812
# Import existing types from the main SDK - REUSE EVERYTHING POSSIBLE
913
from aws_durable_execution_sdk_python.lambda_service import (
@@ -156,11 +160,11 @@ class GetDurableExecutionResponse:
156160
durable_execution_name: str
157161
function_arn: str
158162
status: str
159-
start_timestamp: float
163+
start_timestamp: datetime.datetime
160164
input_payload: str | None = None
161165
result: str | None = None
162166
error: ErrorObject | None = None
163-
end_timestamp: float | None = None
167+
end_timestamp: datetime.datetime | None = None
164168
version: str | None = None
165169

166170
@classmethod
@@ -213,8 +217,8 @@ class Execution:
213217
durable_execution_name: str
214218
function_arn: str
215219
status: str
216-
start_timestamp: float
217-
end_timestamp: float | None = None
220+
start_timestamp: datetime.datetime
221+
end_timestamp: datetime.datetime | None = None
218222

219223
@classmethod
220224
def from_dict(cls, data: dict) -> Execution:
@@ -350,14 +354,14 @@ def to_dict(self) -> dict[str, Any]:
350354
class StopDurableExecutionResponse:
351355
"""Response from stopping a durable execution."""
352356

353-
end_timestamp: float
357+
stop_timestamp: datetime.datetime
354358

355359
@classmethod
356360
def from_dict(cls, data: dict) -> StopDurableExecutionResponse:
357-
return cls(end_timestamp=data["EndTimestamp"])
361+
return cls(stop_timestamp=data["StopTimestamp"])
358362

359363
def to_dict(self) -> dict[str, Any]:
360-
return {"EndTimestamp": self.end_timestamp}
364+
return {"StopTimestamp": self.stop_timestamp}
361365

362366

363367
@dataclass(frozen=True)
@@ -676,7 +680,7 @@ class WaitStartedDetails:
676680
"""Wait started event details."""
677681

678682
duration: int | None = None
679-
scheduled_end_timestamp: str | None = None
683+
scheduled_end_timestamp: datetime.datetime | None = None # Already correct!
680684

681685
@classmethod
682686
def from_dict(cls, data: dict) -> WaitStartedDetails:
@@ -1010,7 +1014,7 @@ class Event:
10101014
"""Event structure from Smithy model."""
10111015

10121016
event_type: str
1013-
event_timestamp: str
1017+
event_timestamp: datetime.datetime
10141018
sub_type: str | None = None
10151019
event_id: int = 1
10161020
operation_id: str | None = None
@@ -1328,8 +1332,8 @@ class ListDurableExecutionsByFunctionRequest:
13281332
qualifier: str | None = None
13291333
durable_execution_name: str | None = None
13301334
status_filter: list[str] | None = None
1331-
time_after: str | None = None
1332-
time_before: str | None = None
1335+
started_after: str | None = None
1336+
started_before: str | None = None
13331337
marker: str | None = None
13341338
max_items: int = 0
13351339
reverse_order: bool | None = None
@@ -1341,8 +1345,8 @@ def from_dict(cls, data: dict) -> ListDurableExecutionsByFunctionRequest:
13411345
qualifier=data.get("Qualifier"),
13421346
durable_execution_name=data.get("DurableExecutionName"),
13431347
status_filter=data.get("StatusFilter"),
1344-
time_after=data.get("TimeAfter"),
1345-
time_before=data.get("TimeBefore"),
1348+
started_after=data.get("StartedAfter"),
1349+
started_before=data.get("StartedBefore"),
13461350
marker=data.get("Marker"),
13471351
max_items=data.get("MaxItems", 0),
13481352
reverse_order=data.get("ReverseOrder"),
@@ -1356,10 +1360,10 @@ def to_dict(self) -> dict[str, Any]:
13561360
result["DurableExecutionName"] = self.durable_execution_name
13571361
if self.status_filter is not None:
13581362
result["StatusFilter"] = self.status_filter
1359-
if self.time_after is not None:
1360-
result["TimeAfter"] = self.time_after
1361-
if self.time_before is not None:
1362-
result["TimeBefore"] = self.time_before
1363+
if self.started_after is not None:
1364+
result["StartedAfter"] = self.started_after
1365+
if self.started_before is not None:
1366+
result["StartedBefore"] = self.started_before
13631367
if self.marker is not None:
13641368
result["Marker"] = self.marker
13651369
if self.max_items is not None:

src/aws_durable_execution_sdk_python_testing/runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def from_svc_operation(
267267

268268
@dataclass(frozen=True)
269269
class WaitOperation(Operation):
270-
scheduled_timestamp: datetime.datetime | None = None
270+
scheduled_end_timestamp: datetime.datetime | None = None
271271

272272
@staticmethod
273273
def from_svc_operation(
@@ -286,8 +286,8 @@ def from_svc_operation(
286286
sub_type=operation.sub_type,
287287
start_timestamp=operation.start_timestamp,
288288
end_timestamp=operation.end_timestamp,
289-
scheduled_timestamp=(
290-
operation.wait_details.scheduled_timestamp
289+
scheduled_end_timestamp=(
290+
operation.wait_details.scheduled_end_timestamp
291291
if operation.wait_details
292292
else None
293293
),

src/aws_durable_execution_sdk_python_testing/web/handlers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,9 @@ def handle(self, parsed_route: Route, request: HTTPRequest) -> HTTPResponse:
578578
if status_filter := self._parse_query_param(request, "statusFilter"):
579579
query_params["StatusFilter"] = [status_filter] # Convert to list
580580
if time_after := self._parse_query_param(request, "timeAfter"):
581-
query_params["TimeAfter"] = time_after
581+
query_params["StartedAfter"] = time_after
582582
if time_before := self._parse_query_param(request, "timeBefore"):
583-
query_params["TimeBefore"] = time_before
583+
query_params["StartedBefore"] = time_before
584584
if marker := self._parse_query_param(request, "marker"):
585585
query_params["Marker"] = marker
586586
if max_items_str := self._parse_query_param(request, "maxItems"):
@@ -608,8 +608,8 @@ def handle(self, parsed_route: Route, request: HTTPRequest) -> HTTPResponse:
608608
status_filter=list_request.status_filter[0]
609609
if list_request.status_filter
610610
else None,
611-
time_after=list_request.time_after,
612-
time_before=list_request.time_before,
611+
time_after=list_request.started_after,
612+
time_before=list_request.started_before,
613613
marker=list_request.marker,
614614
max_items=list_request.max_items
615615
if list_request.max_items > 0

tests/checkpoint/processors/base_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def test_create_wait_details_with_current_operation():
320320
processor = MockProcessor()
321321
scheduled_time = datetime.datetime.now(tz=datetime.UTC)
322322
current_op = Mock()
323-
current_op.wait_details = WaitDetails(scheduled_timestamp=scheduled_time)
323+
current_op.wait_details = WaitDetails(scheduled_end_timestamp=scheduled_time)
324324

325325
wait_options = WaitOptions(wait_seconds=30)
326326
update = OperationUpdate(
@@ -333,7 +333,7 @@ def test_create_wait_details_with_current_operation():
333333
result = processor.create_wait_details(update, current_op)
334334

335335
assert isinstance(result, WaitDetails)
336-
assert result.scheduled_timestamp == scheduled_time
336+
assert result.scheduled_end_timestamp == scheduled_time
337337

338338

339339
def test_create_wait_details_without_current_operation():
@@ -349,7 +349,7 @@ def test_create_wait_details_without_current_operation():
349349
result = processor.create_wait_details(update, None)
350350

351351
assert isinstance(result, WaitDetails)
352-
assert result.scheduled_timestamp > datetime.datetime.now(tz=datetime.UTC)
352+
assert result.scheduled_end_timestamp > datetime.datetime.now(tz=datetime.UTC)
353353

354354

355355
def test_create_wait_details_non_wait_type():

tests/checkpoint/processors/wait_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_process_start_action():
6767
assert result.status == OperationStatus.STARTED
6868
assert result.name == "test-wait"
6969
assert result.wait_details is not None
70-
assert result.wait_details.scheduled_timestamp > datetime.now(UTC)
70+
assert result.wait_details.scheduled_end_timestamp > datetime.now(UTC)
7171

7272
assert len(notifier.wait_timer_calls) == 1
7373
assert notifier.wait_timer_calls[0] == (execution_arn, "wait-123", 30)
@@ -269,7 +269,7 @@ def test_wait_details_created_correctly():
269269
before_time = datetime.now(UTC)
270270
result = processor.process(update, None, notifier, execution_arn)
271271

272-
assert result.wait_details.scheduled_timestamp > before_time
272+
assert result.wait_details.scheduled_end_timestamp > before_time
273273

274274

275275
def test_no_completed_or_failed_calls():

0 commit comments

Comments
 (0)