Skip to content
Open
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
2 changes: 1 addition & 1 deletion cmd/ateapi/internal/controlapi/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ func TestSuspendActor(t *testing.T) {
LatestSnapshotInfo: &ateapipb.SnapshotInfo{
Data: &ateapipb.SnapshotInfo_External{
External: &ateapipb.ExternalSnapshotInfo{
SnapshotUriPrefix: fmt.Sprintf("gs://fake-fake-fake/%s/", name),
SnapshotUriPrefix: "gs://fake-fake-fake/snapshots/",
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/ateapi/internal/controlapi/workflow_suspend.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (s *MarkSuspendingStep) CheckPrerequisite(ctx context.Context, input *Suspe
func (s *MarkSuspendingStep) Execute(ctx context.Context, input *SuspendInput, state *SuspendState) error {
state.Actor.Status = ateapipb.Actor_STATUS_SUSPENDING
snapshotID := time.Now().Format(time.RFC3339) + "-" + rand.Text()
Comment thread
HavenXia marked this conversation as resolved.
state.Actor.InProgressSnapshot = strings.TrimSuffix(state.ActorTemplate.Spec.SnapshotsConfig.Location, "/") + "/" + input.ActorName + "/" + snapshotID
state.Actor.InProgressSnapshot = strings.TrimSuffix(state.ActorTemplate.Spec.SnapshotsConfig.Location, "/") + "/snapshots/" + snapshotID
Comment thread
HavenXia marked this conversation as resolved.
updatedActor, err := s.store.UpdateActor(ctx, state.Actor, state.Actor.GetMetadata().GetVersion())
if err != nil {
return err
Expand Down
32 changes: 32 additions & 0 deletions cmd/ateapi/internal/controlapi/workflow_suspend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ package controlapi

import (
"context"
"strings"
"testing"

"github.com/agent-substrate/substrate/cmd/ateapi/internal/store"
"github.com/agent-substrate/substrate/cmd/ateapi/internal/store/ateredis"
"github.com/agent-substrate/substrate/cmd/ateapi/internal/store/storetest"
atev1alpha1 "github.com/agent-substrate/substrate/pkg/api/v1alpha1"
"github.com/agent-substrate/substrate/pkg/proto/ateapipb"
"github.com/alicebob/miniredis/v2"
"github.com/redis/go-redis/v9"
Expand All @@ -29,6 +31,36 @@ import (
"k8s.io/client-go/tools/cache"
)

func TestMarkSuspendingStep_SnapshotLocation(t *testing.T) {
ctx := context.Background()
persistence := newTestPersistence(t)
actor, err := persistence.CreateActor(ctx, &ateapipb.Actor{
Metadata: &ateapipb.ResourceMetadata{Atespace: "team-a", Name: "actor-1"},
Status: ateapipb.Actor_STATUS_RUNNING,
})
if err != nil {
t.Fatalf("CreateActor: %v", err)
}
state := &SuspendState{
Actor: actor,
ActorTemplate: &atev1alpha1.ActorTemplate{Spec: atev1alpha1.ActorTemplateSpec{
SnapshotsConfig: atev1alpha1.SnapshotsConfig{Location: "gs://bucket/root/"},
}},
}
if err := (&MarkSuspendingStep{store: persistence}).Execute(ctx, &SuspendInput{Atespace: "team-a", ActorName: "actor-1"}, state); err != nil {
t.Fatalf("Execute: %v", err)
}

const prefix = "gs://bucket/root/snapshots/"
snapshotID, ok := strings.CutPrefix(state.Actor.GetInProgressSnapshot(), prefix)
if !ok {
t.Fatalf("snapshot location = %q, want prefix %q", state.Actor.GetInProgressSnapshot(), prefix)
}
if snapshotID == "" {
t.Fatal("snapshot ID is empty")
}
}

// TestSuspendActorWorkflow_RejectedAndIdempotentPaths covers the two
// short-circuit paths of the suspend workflow: rejection by
// MarkSuspendingStep's CheckPrerequisite and the IsComplete idempotent
Expand Down
Loading