Skip to content

[Bug]: unstable map test case #405

Description

@zhongkechen

Expected Behavior

unit tests should always succeed

Actual Behavior

Some unit tests fail frequently

_________________________ test_map_with_min_successful _________________________

durable_runner = <test.conftest.TestRunnerAdapter object at 0x7fb315db76d0>

    @pytest.mark.example
    @pytest.mark.durable_execution(
        handler=map_with_min_successful.handler,
        lambda_function_name="Map with Min Successful",
    )
    def test_map_with_min_successful(durable_runner):
        """Test map with min_successful threshold."""
        with durable_runner:
            result = durable_runner.run(input="test", timeout=10)
    
        assert result.status is InvocationStatus.SUCCEEDED
    
        result_data = deserialize_operation_payload(result.result)
    
        # With min_successful=6, operation completes after reaching 6 successes
        # Due to concurrency (max_concurrency=5), some items may complete before check
        # Items 1-6 succeed, item 10 succeeds, items 7-9 fail
        # Depending on timing, we get 6 or 7 successes
        assert result_data["success_count"] >= 6
        assert result_data["success_count"] <= 7
    
        # Operation stops once min_successful is reached
        # Items 7-9 (which would fail) are never processed
        assert result_data["failure_count"] == 0
        assert result_data["total_count"] == 10
    
        # Verify we got the expected successful results
        # Items 1-6 always succeed (2, 4, 6, 8, 10, 12)
        # Item 10 might also succeed (20) depending on timing
        assert len(result_data["results"]) == result_data["success_count"]
        for result_val in result_data["results"]:
            assert result_val % 2 == 0  # All results should be even (item * 2)
            assert result_val >= 2 and result_val <= 20  # Range: items 1-10 * 2
            assert result_val not in [14, 16, 18]  # Items 7-9 should not be present
    
        # Completion reason should be MIN_SUCCESSFUL_REACHED
        assert result_data["completion_reason"] == "MIN_SUCCESSFUL_REACHED"
    
        # Get the map operation
        map_op = result.get_context("map_min_successful")
        assert map_op is not None
        assert map_op.status is OperationStatus.SUCCEEDED
    
        # All 10 operations may be started, but only some complete before min_successful
        assert len(map_op.child_operations) == 10
    
        # Count operations by status
        succeeded = [
            op for op in map_op.child_operations if op.status is OperationStatus.SUCCEEDED
        ]
        failed = [
            op for op in map_op.child_operations if op.status is OperationStatus.FAILED
        ]
        started = [
            op for op in map_op.child_operations if op.status is OperationStatus.STARTED
        ]
    
        # Should have 6-7 successes, 0 failures, and remaining in STARTED state
>       assert len(succeeded) == result_data["success_count"]
E       AssertionError: assert 7 == 6
E        +  where 7 = len([ContextOperation(operation_id='1712f93e2f51df042e2b933907d75accfe34a48fe4a42a24e0b08131bc72d591', operation_type=<OperationType.CONTEXT: 'CONTEXT'>, status=<OperationStatus.SUCCEEDED: 'SUCCEEDED'>, parent_id='1ced8f5be2db23a6513eba4d819c73806424748a7bc6fa0d792cc1c7d1775a97', name='map-item-0', sub_type=<OperationSubType.MAP_ITERATION: 'MapIteration'>, start_timestamp=datetime.datetime(2026, 5, 29, 23, 2, 10, 15993, tzinfo=datetime.timezone.utc), end_timestamp=datetime.datetime(2026, 5, 29, 23, 2, 10, 118113, tzinfo=datetime.timezone.utc), child_operations=[StepOperation(operation_id='48550629202cb2d0e1bd4f07d826361bbd2defa71565264c01647fc2da0e9b1e', operation_type=<OperationType.STEP: 'STEP'>, status=<OperationStatus.SUCCEEDED: 'SUCCEEDED'>, parent_id='1712f93e2f51df042e2b933907d75accfe34a48fe4a42a24e0b08131bc72d591', name='item_0', sub_type=<OperationSubType.STEP: 'Step'>, start_timestamp=datetime.datetime(2026, 5, 29, 23, 2, 10, 16049, tzinfo=datetime.timezone.utc), end_timestamp=datetime.datetime(2026, 5, 29, 23, 2, 10, 16081, tzinfo=datetime.timezone.utc), child_operations=[], result='2', error=None, attempt=1, next_attempt_timestamp=None)], result='2', error=None), ContextO... ContextOperation(operation_id='231653dfd4b19fda63d322894453160bffee1d93fddec8d1a5fabcd54257046b', operation_type=<OperationType.CONTEXT: 'CONTEXT'>, status=<OperationStatus.SUCCEEDED: 'SUCCEEDED'>, parent_id='1ced8f5be2db23a6513eba4d819c73806424748a7bc6fa0d792cc1c7d1775a97', name='map-item-5', sub_type=<OperationSubType.MAP_ITERATION: 'MapIteration'>, start_timestamp=datetime.datetime(2026, 5, 29, 23, 2, 10, 222981, tzinfo=datetime.timezone.utc), end_timestamp=datetime.datetime(2026, 5, 29, 23, 2, 10, 324978, tzinfo=datetime.timezone.utc), child_operations=[StepOperation(operation_id='52f785f703c0aea3ba6bc753c6fa52d960b5d275d7e96f1cdb6f16d5771aa4e1', operation_type=<OperationType.STEP: 'STEP'>, status=<OperationStatus.SUCCEEDED: 'SUCCEEDED'>, parent_id='231653dfd4b19fda63d322894453160bffee1d93fddec8d1a5fabcd54257046b', name='item_5', sub_type=<OperationSubType.STEP: 'Step'>, start_timestamp=datetime.datetime(2026, 5, 29, 23, 2, 10, 223049, tzinfo=datetime.timezone.utc), end_timestamp=datetime.datetime(2026, 5, 29, 23, 2, 10, 223081, tzinfo=datetime.timezone.utc), child_operations=[], result='12', error=None, attempt=1, next_attempt_timestamp=None)], result='12', error=None), ...])

Steps to Reproduce

N/A

SDK Version

N/A

Python Version

3.14

Is this a regression?

No

Last Working Version

No response

Additional Context

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions