@@ -380,37 +380,37 @@ func writeServerTrustBundle(t *testing.T, server *httptest.Server) string {
380380 return path
381381}
382382
383- // A golden actor's EgressPolicy can land after its boot started, and the
384- // gateway caches the missing policy for a while, so the boot fetch retries
385- // until the origin answers.
386- func TestBootFetchRetriesUntilOK (t * testing.T ) {
387- var calls atomic.Int32
388- origin := httptest .NewTLSServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
389- if calls .Add (1 ) < 3 {
390- w .WriteHeader (http .StatusForbidden )
391- return
392- }
393- w .WriteHeader (http .StatusOK )
394- }))
395- defer origin .Close ()
396-
397- if err := bootFetch (t .Context (), origin .URL , writeServerTrustBundle (t , origin ), 30 * time .Second ); err != nil {
398- t .Fatalf ("bootFetch() error = %v, want nil" , err )
399- }
400- if got := calls .Load (); got != 3 {
401- t .Errorf ("origin saw %d requests, want 3" , got )
383+ // The actor's EgressPolicy exists before it resumes, so the boot fetch makes
384+ // one request and reports its failure.
385+ func TestBootFetch (t * testing.T ) {
386+ tests := []struct {
387+ name string
388+ status int
389+ wantErr string
390+ }{
391+ {name : "origin answers 200" , status : http .StatusOK },
392+ {name : "origin denies" , status : http .StatusForbidden , wantErr : "status 403" },
402393 }
403- }
404-
405- func TestBootFetchFailsAfterBudget (t * testing.T ) {
406- origin := httptest .NewTLSServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
407- w .WriteHeader (http .StatusForbidden )
408- }))
409- defer origin .Close ()
410-
411- err := bootFetch (t .Context (), origin .URL , writeServerTrustBundle (t , origin ), 1500 * time .Millisecond )
412- if err == nil || ! strings .Contains (err .Error (), "status 403" ) {
413- t .Fatalf ("bootFetch() error = %v, want the last status" , err )
394+ for _ , tt := range tests {
395+ t .Run (tt .name , func (t * testing.T ) {
396+ var calls atomic.Int32
397+ origin := httptest .NewTLSServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
398+ calls .Add (1 )
399+ w .WriteHeader (tt .status )
400+ }))
401+ defer origin .Close ()
402+
403+ err := bootFetch (t .Context (), origin .URL , writeServerTrustBundle (t , origin ))
404+ if tt .wantErr == "" && err != nil {
405+ t .Fatalf ("bootFetch() error = %v, want nil" , err )
406+ }
407+ if tt .wantErr != "" && (err == nil || ! strings .Contains (err .Error (), tt .wantErr )) {
408+ t .Fatalf ("bootFetch() error = %v, want %q" , err , tt .wantErr )
409+ }
410+ if got := calls .Load (); got != 1 {
411+ t .Errorf ("origin saw %d requests, want 1" , got )
412+ }
413+ })
414414 }
415415}
416416
@@ -448,3 +448,41 @@ func TestRestoreFetchGatesHealthzOnIdentity(t *testing.T) {
448448 t .Fatalf ("healthz as a restored actor after it fetched = %d, want 200" , got )
449449 }
450450}
451+
452+ // A failed restore fetch leaves healthz at 503, and the next wakeup probe
453+ // starts another fetch.
454+ func TestRestoreFetchRetriesOnNextProbe (t * testing.T ) {
455+ var deny atomic.Bool
456+ deny .Store (true )
457+ origin := httptest .NewTLSServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
458+ if deny .Load () {
459+ w .WriteHeader (http .StatusForbidden )
460+ return
461+ }
462+ w .WriteHeader (http .StatusOK )
463+ }))
464+ defer origin .Close ()
465+ identity := filepath .Join (t .TempDir (), "actor-id" )
466+ if err := os .WriteFile (identity , []byte ("restored" ), 0o600 ); err != nil {
467+ t .Fatal (err )
468+ }
469+ f := & restoreFetch {url : origin .URL , identityFile : identity , trustBundle : writeServerTrustBundle (t , origin ), fetched : "golden" }
470+ healthz := func () int {
471+ rec := httptest .NewRecorder ()
472+ f .healthz (rec , httptest .NewRequest (http .MethodGet , "/healthz" , nil ))
473+ return rec .Code
474+ }
475+
476+ f .fetch ("restored" )
477+ if got := healthz (); got != http .StatusServiceUnavailable {
478+ t .Fatalf ("healthz after a failed fetch = %d, want 503" , got )
479+ }
480+ deny .Store (false )
481+ deadline := time .Now ().Add (10 * time .Second )
482+ for healthz () != http .StatusOK {
483+ if time .Now ().After (deadline ) {
484+ t .Fatal ("healthz did not answer 200 after the origin allowed the fetch" )
485+ }
486+ time .Sleep (50 * time .Millisecond )
487+ }
488+ }
0 commit comments