diff --git a/internal/e2e/suites/demo/demo_test.go b/internal/e2e/suites/demo/demo_test.go index 43dba3183..fee4630e4 100644 --- a/internal/e2e/suites/demo/demo_test.go +++ b/internal/e2e/suites/demo/demo_test.go @@ -146,12 +146,15 @@ func TestActorSnapshotLifecycle(t *testing.T) { if _, err := clients.SubstrateAPI.GetActorSnapshot(ctx, &ateapipb.GetActorSnapshotRequest{Snapshot: snapshotRef}); err != nil { t.Fatalf("failed to get ActorSnapshot: %v", err) } - listed, err := clients.SubstrateAPI.ListActorSnapshots(ctx, &ateapipb.ListActorSnapshotsRequest{Atespace: demoAtespace}) - if err != nil { - t.Fatalf("failed to list ActorSnapshots: %v", err) - } + snapshots := listAllPages(t, func(token string) ([]*ateapipb.ActorSnapshot, string) { + resp, err := clients.SubstrateAPI.ListActorSnapshots(ctx, &ateapipb.ListActorSnapshotsRequest{Atespace: demoAtespace, PageToken: token}) + if err != nil { + t.Fatalf("failed to list ActorSnapshots: %v", err) + } + return resp.GetSnapshots(), resp.GetNextPageToken() + }) found := false - for _, candidate := range listed.GetSnapshots() { + for _, candidate := range snapshots { if candidate.GetMetadata().GetName() == snapshot.GetName() { found = true break @@ -753,13 +756,16 @@ func createActor(ctx context.Context, t *testing.T, clients *e2e.Clients, nsObj }) }() - listResp, err := clients.SubstrateAPI.ListActors(ctx, &ateapipb.ListActorsRequest{Atespace: demoAtespace}) - if err != nil { - t.Fatalf("ListActors RPC failed: %v", err) - } + actors := listAllPages(t, func(token string) ([]*ateapipb.Actor, string) { + resp, err := clients.SubstrateAPI.ListActors(ctx, &ateapipb.ListActorsRequest{Atespace: demoAtespace, PageToken: token}) + if err != nil { + t.Fatalf("ListActors RPC failed: %v", err) + } + return resp.GetActors(), resp.GetNextPageToken() + }) var myActors []*ateapipb.Actor - for _, actor := range listResp.GetActors() { + for _, actor := range actors { if actor.GetActorTemplateNamespace() == nsObj.Name && actor.GetMetadata().GetName() == actorName { myActors = append(myActors, actor) } @@ -782,7 +788,7 @@ func createActor(ctx context.Context, t *testing.T, clients *e2e.Clients, nsObj } t.Logf("Successfully queried Substrate API. Found %d active actors total, %d in our namespace %s.", - len(listResp.GetActors()), len(myActors), nsObj.Name) + len(actors), len(myActors), nsObj.Name) return nil } @@ -1299,6 +1305,21 @@ func hasStorageClass(ctx context.Context, clients *e2e.Clients, name string) boo return err == nil } +// listAllPages drains every page: results are ordered by name, and names are +// UUIDs, so a just-created resource can land on any page. +func listAllPages[T any](t *testing.T, page func(token string) ([]T, string)) []T { + t.Helper() + var all []T + for token := ""; ; { + items, next := page(token) + all = append(all, items...) + if next == "" { + return all + } + token = next + } +} + func waitForActorState(ctx context.Context, t *testing.T, clients *e2e.Clients, actorName string, expectedState ateapipb.ActorState) { waitForActorStateWithTimeout(ctx, t, clients, actorName, expectedState, 60*time.Second) }