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
14 changes: 7 additions & 7 deletions api/propagation.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (ph *PropagatedHistory) chunkEvents(chunk historyChunk) []*protos.HistoryEv
}

// WorkflowResult is a scoped view of a single workflow's chunk in propagated history.
// Use GetActivityByName or GetChildWorkflowByName to query specific items.
// Use GetLastActivityByName or GetLastChildWorkflowByName to query specific items.
type WorkflowResult struct {
Found bool
InstanceID string
Expand Down Expand Up @@ -207,13 +207,13 @@ func (ph *PropagatedHistory) GetWorkflows() []*WorkflowResult {
return results
}

// GetWorkflowByName returns the last workflow chunk in the propagated history
// GetLastWorkflowByName returns the last workflow chunk in the propagated history
// whose workflow name matches. When the chain contains the same workflow name
// more than once (eg a workflow that does ContinueAsNew, or a recursive child
// workflow) this returns the most-recent occurrence — equivalent to the last
// element of GetWorkflowsByName. Returns ErrPropagationNotFound when no chunk
// matches.
func (ph *PropagatedHistory) GetWorkflowByName(name string) (*WorkflowResult, error) {
func (ph *PropagatedHistory) GetLastWorkflowByName(name string) (*WorkflowResult, error) {
all := ph.GetWorkflowsByName(name)
if len(all) == 0 {
return nil, ErrPropagationNotFound
Expand Down Expand Up @@ -259,12 +259,12 @@ func resolveActivity(events []*protos.HistoryEvent, scheduleEvent *protos.Histor
return result
}

// GetActivityByName returns the last activity scheduled in this workflow's
// GetLastActivityByName returns the last activity scheduled in this workflow's
// chunk whose name matches. The returned result reflects the most recent
// invocation; for SDK-driven retries (which reuse the activity name and
// taskExecutionId) this is the final attempt. Returns ErrPropagationNotFound
// when the workflow result is empty or no activity event matches.
func (wr WorkflowResult) GetActivityByName(name string) (*ActivityResult, error) {
func (wr WorkflowResult) GetLastActivityByName(name string) (*ActivityResult, error) {
all := wr.GetActivitiesByName(name)
if len(all) == 0 {
return nil, ErrPropagationNotFound
Expand Down Expand Up @@ -308,13 +308,13 @@ func resolveChildWorkflow(events []*protos.HistoryEvent, eventID int32) *ChildWo
return result
}

// GetChildWorkflowByName returns the last child workflow scheduled in this
// GetLastChildWorkflowByName returns the last child workflow scheduled in this
// workflow's chunk whose name matches. When the same child workflow name is
// invoked more than once from this parent (in a loop), this returns the
// most recent invocation — equivalent to the last element of
// GetChildWorkflowsByName. Returns ErrPropagationNotFound when the workflow
// result is empty or no child workflow event matches.
func (wr WorkflowResult) GetChildWorkflowByName(name string) (*ChildWorkflowResult, error) {
func (wr WorkflowResult) GetLastChildWorkflowByName(name string) (*ChildWorkflowResult, error) {
all := wr.GetChildWorkflowsByName(name)
if len(all) == 0 {
return nil, ErrPropagationNotFound
Expand Down
56 changes: 28 additions & 28 deletions api/propagation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ func TestGetWorkflows(t *testing.T) {
assert.True(t, wfs[1].Found)
}

func TestGetWorkflowByName(t *testing.T) {
func TestGetLastWorkflowByName(t *testing.T) {
ph := makeTestHistory()

wf, err := ph.GetWorkflowByName("ProcessPayment")
wf, err := ph.GetLastWorkflowByName("ProcessPayment")
require.NoError(t, err)
assert.True(t, wf.Found)
assert.Equal(t, "appB", wf.AppID)
assert.Equal(t, "wf-002", wf.InstanceID)

_, err = ph.GetWorkflowByName("NonExistent")
_, err = ph.GetLastWorkflowByName("NonExistent")
require.ErrorIs(t, err, ErrPropagationNotFound)
}

Expand Down Expand Up @@ -153,7 +153,7 @@ func TestGetWorkflowsByName_Duplicates(t *testing.T) {
}

// Singular returns last (most recent)
wf, err := ph.GetWorkflowByName("Worker")
wf, err := ph.GetLastWorkflowByName("Worker")
require.NoError(t, err)
assert.Equal(t, "w-2", wf.InstanceID)
assert.Equal(t, "app2", wf.AppID)
Expand All @@ -165,13 +165,13 @@ func TestGetWorkflowsByName_Duplicates(t *testing.T) {
assert.Equal(t, "w-2", wfs[1].InstanceID)
}

func TestGetActivityByName(t *testing.T) {
func TestGetLastActivityByName(t *testing.T) {
ph := makeTestHistory()
wf, err := ph.GetWorkflowByName("MerchantCheckout")
wf, err := ph.GetLastWorkflowByName("MerchantCheckout")
require.NoError(t, err)

// Activity that completed
act, err := wf.GetActivityByName("ValidateMerchant")
act, err := wf.GetLastActivityByName("ValidateMerchant")
require.NoError(t, err)
assert.True(t, act.Started)
assert.True(t, act.Completed)
Expand All @@ -181,17 +181,17 @@ func TestGetActivityByName(t *testing.T) {
assert.Nil(t, act.Error)

// Activity not found
_, err = wf.GetActivityByName("NonExistent")
_, err = wf.GetLastActivityByName("NonExistent")
require.ErrorIs(t, err, ErrPropagationNotFound)
}

func TestGetActivityByName_ReturnsLast(t *testing.T) {
func TestGetLastActivityByName_ReturnsLast(t *testing.T) {
ph := makeTestHistory()
wf, err := ph.GetWorkflowByName("ProcessPayment")
wf, err := ph.GetLastWorkflowByName("ProcessPayment")
require.NoError(t, err)

// ValidateCard was called twice — singular returns the LAST (failed retry)
act, err := wf.GetActivityByName("ValidateCard")
act, err := wf.GetLastActivityByName("ValidateCard")
require.NoError(t, err)
assert.True(t, act.Started)
assert.False(t, act.Completed)
Expand All @@ -202,7 +202,7 @@ func TestGetActivityByName_ReturnsLast(t *testing.T) {

func TestGetActivitiesByName_Retries(t *testing.T) {
ph := makeTestHistory()
wf, err := ph.GetWorkflowByName("ProcessPayment")
wf, err := ph.GetLastWorkflowByName("ProcessPayment")
require.NoError(t, err)

// ValidateCard was called twice (retry scenario)
Expand All @@ -226,7 +226,7 @@ func TestGetActivitiesByName_Retries(t *testing.T) {

func TestGetActivitiesByName_NotFound(t *testing.T) {
ph := makeTestHistory()
wf, err := ph.GetWorkflowByName("ProcessPayment")
wf, err := ph.GetLastWorkflowByName("ProcessPayment")
require.NoError(t, err)

acts := wf.GetActivitiesByName("NonExistent")
Expand All @@ -235,7 +235,7 @@ func TestGetActivitiesByName_NotFound(t *testing.T) {

func TestGetActivitiesByName_WorkflowNotFound(t *testing.T) {
ph := makeTestHistory()
_, err := ph.GetWorkflowByName("NonExistent")
_, err := ph.GetLastWorkflowByName("NonExistent")
require.ErrorIs(t, err, ErrPropagationNotFound)

// A zero-valued WorkflowResult (not from the API) returns nil for plural lookups.
Expand All @@ -244,10 +244,10 @@ func TestGetActivitiesByName_WorkflowNotFound(t *testing.T) {
assert.Nil(t, acts)
}

// TestGetWorkflowByName_EqualsPluralLast verifies the contract that
// GetWorkflowByName(name) returns the same result as
// TestGetLastWorkflowByName_EqualsPluralLast verifies the contract that
// GetLastWorkflowByName(name) returns the same result as
// GetWorkflowsByName(name)[len-1] when multiple matches exist.
func TestGetWorkflowByName_EqualsPluralLast(t *testing.T) {
func TestGetLastWorkflowByName_EqualsPluralLast(t *testing.T) {
ph := &PropagatedHistory{
events: []*protos.HistoryEvent{
{EventId: 0, EventType: &protos.HistoryEvent_ExecutionStarted{
Expand All @@ -267,7 +267,7 @@ func TestGetWorkflowByName_EqualsPluralLast(t *testing.T) {
},
}

singular, err := ph.GetWorkflowByName("Worker")
singular, err := ph.GetLastWorkflowByName("Worker")
require.NoError(t, err)
plural := ph.GetWorkflowsByName("Worker")

Expand All @@ -285,17 +285,17 @@ func TestGetWorkflowByName_EqualsPluralLast(t *testing.T) {
"singular must differ from plural[0]")
}

// TestGetActivityByName_EqualsPluralLast verifies the contract that
// GetActivityByName(name) returns the same result as
// TestGetLastActivityByName_EqualsPluralLast verifies the contract that
// GetLastActivityByName(name) returns the same result as
// GetActivitiesByName(name)[len-1] when multiple matches exist.
func TestGetActivityByName_EqualsPluralLast(t *testing.T) {
func TestGetLastActivityByName_EqualsPluralLast(t *testing.T) {
// ValidateCard appears twice in the ProcessPayment chunk: once
// completed (first), once failed (retry).
ph := makeTestHistory()
wf, err := ph.GetWorkflowByName("ProcessPayment")
wf, err := ph.GetLastWorkflowByName("ProcessPayment")
require.NoError(t, err)

singular, err := wf.GetActivityByName("ValidateCard")
singular, err := wf.GetLastActivityByName("ValidateCard")
require.NoError(t, err)
plural := wf.GetActivitiesByName("ValidateCard")

Expand All @@ -316,25 +316,25 @@ func TestGetActivityByName_EqualsPluralLast(t *testing.T) {
"singular must differ from plural[0]")
}

func TestGetChildWorkflowByName(t *testing.T) {
func TestGetLastChildWorkflowByName(t *testing.T) {
ph := makeTestHistory()
wf, err := ph.GetWorkflowByName("MerchantCheckout")
wf, err := ph.GetLastWorkflowByName("MerchantCheckout")
require.NoError(t, err)

child, err := wf.GetChildWorkflowByName("ProcessPayment")
child, err := wf.GetLastChildWorkflowByName("ProcessPayment")
require.NoError(t, err)
assert.True(t, child.Started)
assert.Equal(t, "ProcessPayment", child.Name)
// Not completed in our test data (no ChildWorkflowInstanceCompleted event)
assert.False(t, child.Completed)

_, err = wf.GetChildWorkflowByName("NonExistent")
_, err = wf.GetLastChildWorkflowByName("NonExistent")
require.ErrorIs(t, err, ErrPropagationNotFound)
}

func TestGetChildWorkflowsByName(t *testing.T) {
ph := makeTestHistory()
wf, err := ph.GetWorkflowByName("ProcessPayment")
wf, err := ph.GetLastWorkflowByName("ProcessPayment")
require.NoError(t, err)

children := wf.GetChildWorkflowsByName("FraudDetection")
Expand Down
Loading