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
6 changes: 4 additions & 2 deletions cmd/ateapi/internal/controlapi/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ var (
ignoreUID = protocmp.IgnoreFields(&ateapipb.ResourceMetadata{}, "uid")
ignoreVersion = protocmp.IgnoreFields(&ateapipb.ResourceMetadata{}, "version")
ignoreTimestamps = protocmp.IgnoreFields(&ateapipb.ResourceMetadata{}, "create_time", "update_time")
ignoreResumeTime = protocmp.IgnoreFields(&ateapipb.Actor{}, "last_resume_time")
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -1750,7 +1751,7 @@ func TestResumeActor(t *testing.T) {
WorkerPodIp: "127.0.0.1",
},
}
if diff := cmp.Diff(want, getResp, protocmp.Transform(), ignoreUID, ignoreVersion, ignoreTimestamps, protocmp.IgnoreFields(&ateapipb.WorkerAssignment{}, "worker_pod_uid")); diff != "" {
if diff := cmp.Diff(want, getResp, protocmp.Transform(), ignoreUID, ignoreVersion, ignoreTimestamps, ignoreResumeTime, protocmp.IgnoreFields(&ateapipb.WorkerAssignment{}, "worker_pod_uid")); diff != "" {
t.Errorf("GetActor response mismatch (-want +got):\n%s", diff)
}

Expand Down Expand Up @@ -2226,7 +2227,7 @@ func TestSuspendActor(t *testing.T) {
ignoreUID,
ignoreVersion,
ignoreTimestamps,
protocmp.IgnoreFields(&ateapipb.Actor{}, "latest_snapshot"),
protocmp.IgnoreFields(&ateapipb.Actor{}, "latest_snapshot", "last_resume_time"),
); diff != "" {
t.Errorf("GetActor response mismatch (-want +got):\n%s", diff)
}
Expand Down Expand Up @@ -2318,6 +2319,7 @@ func TestPauseActor(t *testing.T) {
ignoreUID,
ignoreVersion,
ignoreTimestamps,
ignoreResumeTime,
protocmp.IgnoreFields(&ateapipb.WorkerAssignment{}, "worker_pod_uid"),
protocmp.IgnoreFields(&ateapipb.LocalSnapshotInfo{}, "snapshot_name"),
); diff != "" {
Expand Down
2 changes: 2 additions & 0 deletions cmd/ateapi/internal/controlapi/workflow_resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -762,6 +763,7 @@ func (w *ActorWorkflow) finalizeRunning(ctx context.Context, actorRef resources.

storedActor, err := w.store.UpdateActor(ctx, actorRef, store.WithPrecondition(latestActor, func(toUpdate *ateapipb.Actor) error {
toUpdate.Status = ateapipb.Actor_STATUS_RUNNING
toUpdate.LastResumeTime = timestamppb.Now()
return nil
}))
if err != nil {
Expand Down
30 changes: 30 additions & 0 deletions cmd/ateapi/internal/controlapi/workflow_resume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,36 @@ func TestResumeActor_CrashesOnMissingWorkerAssignment(t *testing.T) {
}
}

func TestFinalizeRunning_SetsLastResumeTime(t *testing.T) {
ctx := context.Background()
st, cleanup := storetest.SetupTestStore(t)
defer cleanup()
w := newTestActorWorkflow(t, st, "ns", "tmpl1")

ref := resources.ActorRef{Atespace: "team-a", Name: "id1"}
seedWorkflowActor(t, ctx, st, ref, "ns", "tmpl1", ateapipb.Actor_STATUS_RESUMING)

before := time.Now()
if _, err := w.finalizeRunning(ctx, ref); err != nil {
t.Fatalf("finalizeRunning: %v", err)
}

got, err := st.GetActor(ctx, ref)
if err != nil {
t.Fatalf("GetActor: %v", err)
}
if got.GetStatus() != ateapipb.Actor_STATUS_RUNNING {
t.Errorf("status = %v, want RUNNING", got.GetStatus())
}
lrt := got.GetLastResumeTime()
if lrt == nil {
t.Fatal("LastResumeTime not set")
}
if ts := lrt.AsTime(); ts.Before(before.Add(-time.Second)) || ts.After(time.Now().Add(time.Second)) {
t.Errorf("LastResumeTime = %v, want within test window", ts)
}
}

// TestValidateAssignedWorker_WorkerOwnership verifies that RESUMING recovery
// only proceeds on a worker whose assignment still names this actor: the
// recovery path loads the worker by pod name only, so the assignment may have
Expand Down
35 changes: 35 additions & 0 deletions cmd/ateapi/internal/controlapi/workflow_suspend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"errors"
"testing"
"time"

"github.com/agent-substrate/substrate/cmd/ateapi/internal/store"
"github.com/agent-substrate/substrate/cmd/ateapi/internal/store/ateredis"
Expand All @@ -30,6 +31,7 @@ import (
"github.com/redis/go-redis/v9"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -366,6 +368,39 @@ func TestEnsureSuspendedFinalized_NoAssignment(t *testing.T) {
}
}

// LastResumeTime records the last transition into RUNNING, so suspending must
// leave it alone: it stays queryable while the actor is suspended.
func TestEnsureSuspendedFinalized_KeepsLastResumeTime(t *testing.T) {
ctx := context.Background()
persistence := newTestPersistence(t)

resumedAt := timestamppb.New(time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC))
actor := &ateapipb.Actor{
Metadata: &ateapipb.ResourceMetadata{Atespace: "team-a", Name: "actor-1"},
Status: ateapipb.Actor_STATUS_SUSPENDING,
InProgressSnapshotName: "2026-01-01t00-00-00z-abc",
InProgressSnapshotSourceActorVersion: 1,
LastResumeTime: resumedAt,
}
if _, err := persistence.CreateActor(ctx, actor); err != nil {
t.Fatalf("CreateActor: %v", err)
}

w := &ActorWorkflow{store: persistence}
tmpl := &atev1alpha1.ActorTemplate{Spec: atev1alpha1.ActorTemplateSpec{SnapshotsConfig: atev1alpha1.SnapshotsConfig{Location: "gs://snapshots"}}}
stored, err := w.ensureSuspendedFinalized(ctx, resources.ActorRef{Atespace: "team-a", Name: "actor-1"}, tmpl)
if err != nil {
t.Fatalf("ensureSuspendedFinalized: %v", err)
}

if stored.GetStatus() != ateapipb.Actor_STATUS_SUSPENDED {
t.Errorf("status = %v, want SUSPENDED", stored.GetStatus())
}
if got := stored.GetLastResumeTime(); !got.AsTime().Equal(resumedAt.AsTime()) {
t.Errorf("LastResumeTime = %v, want %v preserved through suspend", got.AsTime(), resumedAt.AsTime())
}
}

func TestEnsureSuspendedFinalized_ReleasesOnlyOwnWorker(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading