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
8 changes: 8 additions & 0 deletions tests/orchestrator/orchestrator_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from azure.durable_functions.models import DurableOrchestrationContext, DurableEntityContext
from azure.durable_functions.orchestrator import Orchestrator
from azure.durable_functions.entity import Entity
from .schemas.EntityStateSchema import schema as entity_state_schema
from .schemas.OrchetrationStateSchema import schema


Expand Down Expand Up @@ -122,6 +123,13 @@ def assert_valid_schema(orchestration_state):
assert validation_results is None


def assert_valid_entity_schema(entity_state):
validation_results = validate(
instance=entity_state,
schema=entity_state_schema)
assert validation_results is None


def assert_dict_are_equal(expected: Dict[Any, Any], result: Dict[Any, Any]):
assert len(expected.keys()) == len(result.keys())
for key in expected.keys():
Expand Down
43 changes: 43 additions & 0 deletions tests/orchestrator/schemas/EntityStateSchema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"entityExists": {"type": "boolean"},
"entityState": {"type": "string"},
"results": {
"type": "array",
"items": {
"type": "object",
"properties": {
"isError": {"type": "boolean"},
"duration": {
"type": "integer",
"minimum": 0
},
"startTime": {
"type": "integer",
"minimum": 0
},
"result": {"type": "string"}
},
"required": [
"isError",
"duration",
"startTime",
"result"
],
"additionalProperties": False
}
},
"signals": {
"type": "array"
}
},
"required": [
"entityExists",
"entityState",
"results",
"signals"
],
"additionalProperties": False
}
221 changes: 171 additions & 50 deletions tests/orchestrator/schemas/OrchetrationStateSchema.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,187 @@
from azure.durable_functions.models.ReplaySchema import ReplaySchema
from azure.durable_functions.models.actions.ActionType import ActionType


def _action_schema(action_type, properties, required):
return {
"type": "object",
"properties": {
"actionType": {"const": action_type.value},
**properties
},
"required": ["actionType", *required],
"additionalProperties": False
}


_retry_options = {
"type": "object",
"properties": {
"firstRetryIntervalInMilliseconds": {
"type": "integer",
"minimum": 1
},
"maxNumberOfAttempts": {"type": "integer"}
},
"required": [
"firstRetryIntervalInMilliseconds",
"maxNumberOfAttempts"
],
"additionalProperties": False
}

_entity_action_properties = {
"instanceId": {"type": "string"},
"operation": {"type": "string"},
"input": {"type": "string"}
}

_sub_orchestrator_properties = {
"functionName": {"type": "string"},
"input": {"type": "string"},
"instanceId": {"type": ["string", "null"]},
"version": {"type": ["string", "null"]}
}

_http_request = {
"type": "object",
"properties": {
"method": {"type": "string"},
"uri": {"type": "string"},
"content": {"type": ["string", "null"]},
"headers": {
"type": ["object", "null"],
"additionalProperties": {"type": "string"}
},
"tokenSource": {
"type": "object",
"properties": {
"kind": {"const": "AzureManagedIdentity"},
"resource": {"type": "string"}
},
"required": ["kind", "resource"],
"additionalProperties": False
}
},
"required": ["method", "uri"],
"additionalProperties": False
}

schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"definitions": {
"action": {
"oneOf": [
_action_schema(
ActionType.CALL_ACTIVITY,
{
"functionName": {"type": "string"},
"input": {"type": "string"}
},
["functionName", "input"]
),
_action_schema(
ActionType.CALL_ACTIVITY_WITH_RETRY,
{
"functionName": {"type": "string"},
"input": {"type": "string"},
"retryOptions": _retry_options
},
["functionName", "input", "retryOptions"]
),
_action_schema(
ActionType.CALL_SUB_ORCHESTRATOR,
_sub_orchestrator_properties,
["functionName", "input"]
),
_action_schema(
ActionType.CALL_SUB_ORCHESTRATOR_WITH_RETRY,
{
**_sub_orchestrator_properties,
"retryOptions": _retry_options
},
["functionName", "input", "retryOptions"]
),
_action_schema(
ActionType.CONTINUE_AS_NEW,
{"input": {"type": "string"}},
["input"]
),
_action_schema(
ActionType.CREATE_TIMER,
{
"fireAt": {
"type": "string",
"format": "date-time"
},
"isCanceled": {"type": "boolean"}
},
["fireAt", "isCanceled"]
),
_action_schema(
ActionType.WAIT_FOR_EXTERNAL_EVENT,
{
"externalEventName": {"type": "string"},
"reason": {"const": "ExternalEvent"}
},
["externalEventName", "reason"]
),
_action_schema(
ActionType.CALL_ENTITY,
_entity_action_properties,
["instanceId", "operation", "input"]
),
_action_schema(
ActionType.CALL_HTTP,
{"httpRequest": _http_request},
["httpRequest"]
),
_action_schema(
ActionType.SIGNAL_ENTITY,
_entity_action_properties,
["instanceId", "operation", "input"]
),
_action_schema(
ActionType.WHEN_ANY,
{
"compoundActions": {
"type": "array",
"items": {"$ref": "#/definitions/action"}
}
},
["compoundActions"]
),
_action_schema(
ActionType.WHEN_ALL,
{
"compoundActions": {
"type": "array",
"items": {"$ref": "#/definitions/action"}
}
},
["compoundActions"]
)
]
}
},
"properties": {
"isDone": {"type": "boolean"},
"schemaVersion": {
"type": "integer",
"enum": [ReplaySchema.V2.value, ReplaySchema.V3.value]
},
"output": {},
"error": {"type": "string"},
"customStatus": {
"anyOf": [
{
"type": "object",
},{
"type": "string",
}] },
"customStatus": {},
"actions": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"functionName": {"type": "string"},
"actionType": {"type": "number"},
"input": {},
"retryOptions": {
"type": "object",
"properties": {
"firstRetryIntervalInMilliseconds": {
"type": "number",
"minimum": 1},
"maxNumberOfAttempts": {"type": "number"}
},
"required":
["firstRetryIntervalInMilliseconds", "maxNumberOfAttempts"],
"additionalProperties": False
},
"httpRequest": {
"type": "object",
"properties": {
"method": {"type": "string"},
"uri": {"type": "string"},
"content": {},
"headers": {},
"tokenSource": {
"type": "object",
"properties": {
"resource": {"type": "string"}
},
"required": ["resource"],
"additionalProperties": False
}
},
"required":
["method", "uri"],
"additionalProperties": False
}
},
"required": ["actionType"],
"additionalProperties": False
}
"items": {"$ref": "#/definitions/action"}
}
}
},
"required": ["isDone"],
"required": ["isDone", "actions"],
"additionalProperties": False
}
4 changes: 2 additions & 2 deletions tests/orchestrator/test_call_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_initial_post_state():
add_http_action(expected_state, request)
expected = expected_state.to_json()

# assert_valid_schema(result)
assert_valid_schema(result)
assert_orchestration_state_equals(expected, result)
validate_result_http_request(result)

Expand Down Expand Up @@ -172,7 +172,7 @@ def test_post_completed_state():
expected_state._is_done = True
expected = expected_state.to_json()

# assert_valid_schema(result)
assert_valid_schema(result)
assert_orchestration_state_equals(expected, result)
validate_result_http_request(result)

Expand Down
4 changes: 1 addition & 3 deletions tests/orchestrator/test_create_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def test_timers_comparison_with_relaxed_precision():
expected_state._is_done = True
expected = expected_state.to_json()

#assert_valid_schema(result)
# TODO: getting the following error when validating the schema
# "Additional properties are not allowed ('fireAt', 'isCanceled' were unexpected)">
assert_valid_schema(result)
assert_orchestration_state_equals(expected, result)

def test_timers_can_be_cancelled():
Expand Down
Loading
Loading