Skip to content
Open
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
43 changes: 32 additions & 11 deletions internal/e2e/suites/demo/demo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down