@@ -5,14 +5,17 @@ import (
55 "context"
66 "fmt"
77 "io/ioutil"
8+ "net"
89 "net/http"
910 "net/http/httptest"
11+ "strings"
1012 "testing"
1113 "time"
1214
1315 feastSdk "github.com/feast-dev/feast/sdk/go"
1416 "github.com/feast-dev/feast/sdk/go/protos/feast/serving"
1517 feastTypes "github.com/feast-dev/feast/sdk/go/protos/feast/types"
18+ "github.com/gorilla/mux"
1619 "github.com/stretchr/testify/assert"
1720 "github.com/stretchr/testify/mock"
1821 "go.uber.org/zap"
@@ -764,3 +767,41 @@ func respBody(t *testing.T, response *http.Response) string {
764767
765768 return string (respBody )
766769}
770+
771+ func Test_recoveryHandler (t * testing.T ) {
772+ router := mux .NewRouter ()
773+ logger , _ := zap .NewDevelopment ()
774+
775+ ts := httptest .NewServer (nil )
776+ defer ts .Close ()
777+
778+ port := fmt .Sprint (ts .Listener .Addr ().(* net.TCPAddr ).Port )
779+ modelName := "test-panic"
780+
781+ s := & Server {
782+ router : router ,
783+ logger : logger ,
784+ options : & Options {
785+ Port : port ,
786+ ModelName : modelName ,
787+ },
788+ PreprocessHandler : func (ctx context.Context , rawRequest []byte , rawRequestHeaders map [string ]string ) ([]byte , error ) {
789+ panic ("panic at preprocess" )
790+ return nil , nil
791+ },
792+ }
793+ go s .Run ()
794+
795+ // Give some time for the server to run.
796+ time .Sleep (1 * time .Second )
797+
798+ resp , err := http .Post (fmt .Sprintf ("http://localhost:%s/v1/models/%s:predict" , port , modelName ), "" , strings .NewReader ("{}" ))
799+ assert .Nil (t , err )
800+ assert .Equal (t , http .StatusInternalServerError , resp .StatusCode )
801+
802+ respBody , err := ioutil .ReadAll (resp .Body )
803+ defer resp .Body .Close ()
804+
805+ assert .Nil (t , err )
806+ assert .Equal (t , `{"code":500,"message":"panic: panic at preprocess"}` , string (respBody ))
807+ }
0 commit comments