@@ -102,22 +102,6 @@ func seedWorker(t *testing.T, ctx context.Context, st store.Interface, actorRef
102102 seedAssignment (t , st , "uid" , assignment )
103103}
104104
105- // seedUnboundActor stores a running actor whose worker-binding fields were
106- // already cleared, e.g. by a prior release.
107- func seedUnboundActor (t * testing.T , ctx context.Context , st store.Interface , actorRef resources.ActorRef ) {
108- t .Helper ()
109- storetest .MustCreateActor (t , ctx , st , & ateapi.Actor {
110- Metadata : & ateapi.ResourceMetadata {Name : actorRef .Name , Atespace : actorRef .Atespace },
111- Status : & ateapi.ActorStatus {
112- State : ateapi .ActorState_ACTOR_STATE_RUNNING ,
113- LastAssignedGeneration : 1 ,
114- Snapshots : []* ateapi.Snapshot {
115- newDurableSnapshot (1 , ateapi .SnapshotOwner_SNAPSHOT_OWNER_ACTOR , ateapi .SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY , "" , "reserved-snapshot" , "gs://bucket/atespaces/as/actors/uid/snapshots/reserved-snapshot" , ateapi .SnapshotStorageState_SNAPSHOT_STORAGE_STATE_PENDING ),
116- },
117- },
118- })
119- }
120-
121105// assertCrashed reloads the actor and verifies it is CRASHED with its worker
122106// binding cleared.
123107func assertCrashed (t * testing.T , ctx context.Context , st store.Interface , actorRef resources.ActorRef ) {
@@ -236,26 +220,6 @@ func TestCrashActor(t *testing.T) {
236220 }
237221 },
238222 },
239- {
240- name : "skips release for actor with no worker binding" ,
241- seed : false ,
242- setup : func (t * testing.T , ctx context.Context , st store.Interface ) {
243- seedUnboundActor (t , ctx , st , actorRef )
244- seedWorker (t , ctx , st , actorRef )
245- },
246- check : func (t * testing.T , ctx context.Context , st store.Interface , err error ) {
247- if err != nil {
248- t .Fatalf ("crashActor() = %v, want nil" , err )
249- }
250- assertCrashed (t , ctx , st , actorRef )
251- // Without a binding the worker cannot be looked up, so its
252- // assignment must be left untouched even though it names
253- // the crashed actor.
254- if firstAssignment (t , st , "uid" ) == nil {
255- t .Error ("worker assignment = nil, want untouched" )
256- }
257- },
258- },
259223 {
260224 name : "actor not found" ,
261225 seed : false ,
@@ -317,7 +281,7 @@ func TestCrashActor_RecordsCrash(t *testing.T) {
317281 }
318282
319283 // Crashing an already-crashed actor, as a concurrent crash does, keeps the first crash.
320- if err := crashActor (ctx , st , actorRef , ateattr .OperationResume , crashMessageWorkerGone ); err != nil {
284+ if err := crashActor (ctx , st , actorRef , ateattr .OperationResume , crashMessageWorkerIneligible ); err != nil {
321285 t .Fatalf ("second crashActor() = %v, want nil" , err )
322286 }
323287 second , err := st .GetActor (ctx , actorRef )
@@ -511,8 +475,8 @@ func TestNewActorCrash(t *testing.T) {
511475 {
512476 name : "known operation prefixes the message" ,
513477 opName : ateattr .OperationResume ,
514- message : crashMessageWorkerGone ,
515- want : resumeOpPrefix + crashMessageWorkerGone ,
478+ message : crashMessageWorkerDraining ,
479+ want : resumeOpPrefix + crashMessageWorkerDraining ,
516480 },
517481 {
518482 name : "unknown operation leaves the message bare" ,
@@ -667,61 +631,17 @@ func assertNoCrashMetricDatapoint(t *testing.T, reader *sdkmetric.ManualReader)
667631 }
668632}
669633
670- // failingReleaseStore wraps a store and fails every release , simulating a
671- // transient state-store error while releasing a worker .
672- type failingReleaseStore struct {
634+ // failingCrashStore wraps a store and fails every crash write , simulating a
635+ // transient state-store error.
636+ type failingCrashStore struct {
673637 store.Interface
674638 err error
675639}
676640
677- func (f failingReleaseStore ) ReleaseActorFromWorker (context.Context , string , string ) (* ateapi.Worker , error ) {
641+ func (f failingCrashStore ) UpdateActorAndRelease (context.Context , resources. ActorRef , store. Precondition , func ( * ateapi. Actor ) error ) (* ateapi.Actor , error ) {
678642 return nil , f .err
679643}
680644
681- // A transient failure releasing the worker must not move the actor to the
682- // CRASHED state: doing so would strand the still-assigned worker with
683- // no actor left to drive a retry, permanently consuming the worker slot.
684- // crashActor must return the error with the actor and worker left intact so the
685- // caller retries and the worker is reclaimed.
686- func TestCrashActorReleaseFailureLeavesWorkerReclaimable (t * testing.T ) {
687- ctx := context .Background ()
688- actorRef := resources.ActorRef {Atespace : "team-a" , Name : "actor-1" }
689-
690- st , cleanup := storetest .SetupTestStore (t )
691- defer cleanup ()
692- seedActor (t , ctx , st , actorRef )
693- seedWorker (t , ctx , st , actorRef )
694-
695- releaseErr := errors .New ("state store unavailable" )
696- err := crashActor (ctx , failingReleaseStore {Interface : st , err : releaseErr }, actorRef , ateattr .OperationUnknown , "test crash" )
697-
698- if err == nil {
699- t .Fatal ("crashActor() = nil, want error" )
700- }
701- if ! errors .Is (err , releaseErr ) {
702- t .Errorf ("crashActor() error = %v, want it to wrap %v" , err , releaseErr )
703- }
704-
705- // The actor must stay RUNNING with its worker assignment intact, so a retry
706- // can re-release the worker.
707- got , gerr := st .GetActor (ctx , actorRef )
708- if gerr != nil {
709- t .Fatalf ("GetActor() = %v, want nil" , gerr )
710- }
711- if got .GetStatus ().GetState () != ateapi .ActorState_ACTOR_STATE_RUNNING {
712- t .Errorf ("status = %v, want %v (actor must not be crashed when the release fails)" , got .GetStatus ().GetState (), ateapi .ActorState_ACTOR_STATE_RUNNING )
713- }
714- if got .GetStatus ().GetWorkerAssignment () == nil {
715- t .Error ("WorkerAssignment cleared, want preserved so the release can be retried" )
716- }
717-
718- // The worker must still be assigned to the actor (the failed release did not
719- // persist): it is not leaked, and a retry will reclaim it.
720- if firstAssignment (t , st , "uid" ) == nil {
721- t .Error ("worker assignment = nil, want still assigned (release failed, must remain retriable)" )
722- }
723- }
724-
725645// TestCrashActorAndFail verifies the error a workflow step fails with when it
726646// crashes the actor: FailedPrecondition once the crash commits, since no retry
727647// can finish the step, but the crash's own error when it does not, leaving the
@@ -736,7 +656,7 @@ func TestCrashActorAndFail(t *testing.T) {
736656 seedActor (t , ctx , st , actorRef )
737657 seedWorker (t , ctx , st , actorRef )
738658
739- err := crashActorAndFail (ctx , st , actorRef , ateattr .OperationSuspend , crashMessageLocalSnapshotMissing )
659+ err := crashActorAndFail (ctx , st , actorRef , ateattr .OperationSuspend , crashMessageSnapshotStateConflict )
740660 if got := apierror .Code (err ); got != codes .FailedPrecondition {
741661 t .Fatalf ("apierror.Code(err) = %v, want %v (err: %v)" , got , codes .FailedPrecondition , err )
742662 }
@@ -750,7 +670,7 @@ func TestCrashActorAndFail(t *testing.T) {
750670 seedWorker (t , ctx , st , actorRef )
751671
752672 releaseErr := errors .New ("state store unavailable" )
753- err := crashActorAndFail (ctx , failingReleaseStore {Interface : st , err : releaseErr }, actorRef , ateattr .OperationSuspend , crashMessageLocalSnapshotMissing )
673+ err := crashActorAndFail (ctx , failingCrashStore {Interface : st , err : releaseErr }, actorRef , ateattr .OperationSuspend , crashMessageSnapshotStateConflict )
754674 if ! errors .Is (err , releaseErr ) {
755675 t .Fatalf ("crashActorAndFail() = %v, want it to wrap %v" , err , releaseErr )
756676 }
@@ -765,6 +685,20 @@ func TestCrashActorAndFail(t *testing.T) {
765685 t .Errorf ("status = %v, want %v (the crash did not commit)" , got .GetStatus ().GetState (), ateapi .ActorState_ACTOR_STATE_RUNNING )
766686 }
767687 })
688+
689+ t .Run ("conflicting crash is Aborted" , func (t * testing.T ) {
690+ st , cleanup := storetest .SetupTestStore (t )
691+ defer cleanup ()
692+ seedActor (t , ctx , st , actorRef )
693+ seedWorker (t , ctx , st , actorRef )
694+
695+ for _ , conflict := range []error {store .ErrVersionConflict , store .ErrUIDConflict } {
696+ err := crashActorAndFail (ctx , failingCrashStore {Interface : st , err : conflict }, actorRef , ateattr .OperationSuspend , crashMessageSnapshotStateConflict )
697+ if got := apierror .Code (err ); got != codes .Aborted {
698+ t .Errorf ("apierror.Code(err) for %v = %v, want %v (err: %v)" , conflict , got , codes .Aborted , err )
699+ }
700+ }
701+ })
768702}
769703
770704// crashRecords captures the "Actor crashed" records a crash emits, so a test can
0 commit comments