Skip to content

Commit

Permalink
Add test for progressive call results
Browse files Browse the repository at this point in the history
  • Loading branch information
muzzammilshahid committed Sep 20, 2024
1 parent 1c5fa0e commit 9269cf5
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,43 @@ func TestPublishSubscribe(t *testing.T) {
log.Println(event)
})
}

func TestProgressiveCallResults(t *testing.T) {
session := connect(t)

reg, err := session.Register(
"foo.bar.progress",
func(ctx context.Context, invocation *xconn.Invocation) (*xconn.Result, *xconn.Error) {
// Send progress
for i := 1; i <= 3; i++ {
err := invocation.SendProgress([]any{i}, nil)
require.NoError(t, err)
}

// Return final result
return &xconn.Result{Args: []any{"done"}}, nil
},
nil,
)
require.NoError(t, err)
require.NotNil(t, reg)

t.Run("ProgressiveCall", func(t *testing.T) {
// Store received progress updates
progressUpdates := make([]int, 0)

result, err := session.Call(context.Background(), "foo.bar.progress", nil, nil, nil,
func(progressiveResult *xconn.Result) {
progress := int(progressiveResult.Args[0].(float64))
// Collect received progress
progressUpdates = append(progressUpdates, progress)
})
require.NoError(t, err)

// Verify progressive updates received correctly
require.Equal(t, []int{1, 2, 3}, progressUpdates)

// Verify the final result
require.Equal(t, "done", result.Args[0])
})
}

0 comments on commit 9269cf5

Please sign in to comment.