package engine
import("context";"errors";"sync/atomic";"testing")
func metric(r Result,name string)int{for _,m:=range r.Metrics{if m[0]==name{return m[1].(int)}};return -1}
func TestCapacityAndCleanup(t *testing.T){for _,variant:=range []string{"broken","safe"}{r,err:=Run(context.Background(),Config{"slow",variant});if err!=nil{t.Fatal(err)};if metric(r,"Active at finish")!=0{t.Fatal("unfinished attempts")};if variant=="safe"&&metric(r,"Peak in flight")>3{t.Fatal("bulkhead exceeded")};if variant=="safe"&&metric(r,"Shed before work")==0{t.Fatal("expected load shedding")}}}
func TestRetryClassification(t *testing.T){var n atomic.Int32;_,err:=Execute(context.Background(),Config{"slow","safe"},func(context.Context,int,int)error{n.Add(1);return errors.New("invalid input")});if err!=nil{t.Fatal(err)};if n.Load()>12{t.Fatal("permanent error retried")}}
func TestRecoveryAndValidation(t *testing.T){r,err:=Run(context.Background(),Config{"recovery","safe"});if err!=nil{t.Fatal(err)};if metric(r,"Succeeded")==0||metric(r,"Circuit skips")==0{t.Fatal("expected circuit recovery")};if _,err=Run(context.Background(),Config{"unknown","safe"});err==nil{t.Fatal("unknown preset accepted")}}
