Skip to content

Commit

Permalink
fix: Bug improvement due to previous logic of mergeWithArchivedWorkfl…
Browse files Browse the repository at this point in the history
…ows function

Signed-off-by: sunyeongchoi <sn0716@naver.com>
  • Loading branch information
sunyeongchoi committed Sep 7, 2023
1 parent bd50093 commit 8713736
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions server/workflow/workflow_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func cursorPaginationByResourceVersion(items []v1alpha1.Workflow, resourceVersio
}
}

func mergeWithArchivedWorkflows(liveWfs v1alpha1.WorkflowList, archivedWfs v1alpha1.WorkflowList, resourceVersion string, limit int64) *v1alpha1.WorkflowList {
func mergeWithArchivedWorkflows(liveWfs v1alpha1.WorkflowList, archivedWfs v1alpha1.WorkflowList) *v1alpha1.WorkflowList {
var mergedWfs []v1alpha1.Workflow
var uidToWfs = map[types.UID][]v1alpha1.Workflow{}
for _, item := range liveWfs.Items {
Expand Down Expand Up @@ -234,7 +234,7 @@ func (s *workflowServer) ListWorkflows(ctx context.Context, req *workflowpkg.Wor
log.Warnf("unable to list archived workflows:%v", err)
} else {
if archivedWfList != nil {
wfList = mergeWithArchivedWorkflows(*wfList, *archivedWfList, resourceVersion, limit)
wfList = mergeWithArchivedWorkflows(*wfList, *archivedWfList)
}
}
cursorPaginationByResourceVersion(wfList.Items, resourceVersion, limit, wfList)
Expand Down
26 changes: 21 additions & 5 deletions server/workflow/workflow_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,27 @@ func TestMergeWithArchivedWorkflows(t *testing.T) {
wf3 := v1alpha1.Workflow{
ObjectMeta: metav1.ObjectMeta{UID: "3", CreationTimestamp: metav1.Time{Time: timeNow.Add(3 * time.Second)}}}
liveWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf1Live, wf2}}
archivedWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf1Archived, wf3, wf2}}
expectedWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf3, wf2, wf1Live}}
expectedShortWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf3, wf2}}
assert.Equal(t, expectedWfList.Items, mergeWithArchivedWorkflows(liveWfList, archivedWfList, 0).Items)
assert.Equal(t, expectedShortWfList.Items, mergeWithArchivedWorkflows(liveWfList, archivedWfList, 2).Items)
archivedWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf3, wf2, wf1Archived}}
expectedWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf1Archived, wf2, wf3}}
assert.Equal(t, expectedWfList.Items, mergeWithArchivedWorkflows(liveWfList, archivedWfList).Items)
}

func TestCursorPaginationByResourceVersion(t *testing.T) {
timeNow := time.Now()
wf1Live := v1alpha1.Workflow{
ObjectMeta: metav1.ObjectMeta{UID: "1", CreationTimestamp: metav1.Time{Time: timeNow.Add(time.Second)},
Labels: map[string]string{common.LabelKeyWorkflowArchivingStatus: "Archived"}}}
wf1Archived := v1alpha1.Workflow{
ObjectMeta: metav1.ObjectMeta{UID: "1", CreationTimestamp: metav1.Time{Time: timeNow.Add(time.Second)},
Labels: map[string]string{common.LabelKeyWorkflowArchivingStatus: "Persisted"}}}
wf2 := v1alpha1.Workflow{
ObjectMeta: metav1.ObjectMeta{UID: "2", CreationTimestamp: metav1.Time{Time: timeNow.Add(2 * time.Second)}}}
wf3 := v1alpha1.Workflow{
ObjectMeta: metav1.ObjectMeta{UID: "3", CreationTimestamp: metav1.Time{Time: timeNow.Add(3 * time.Second)}}}
liveWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf1Live, wf2}}
archivedWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf3, wf2, wf1Archived}}
expectedWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf1Live, wf2, wf3}}
assert.Equal(t, expectedWfList.Items, mergeWithArchivedWorkflows(liveWfList, archivedWfList).Items)
}

func TestWatchWorkflows(t *testing.T) {
Expand Down

0 comments on commit 8713736

Please sign in to comment.