@@ -592,13 +592,13 @@ func TestGetRandomPod(t *testing.T) {
592592 }
593593}
594594
595- func TestDirector_HandleResponse (t * testing.T ) {
596- pr1 := newTestPostResponse ("pr1" )
595+ func TestDirector_HandleResponseRecieved (t * testing.T ) {
596+ pr1 := newTestPostResponseRecieved ("pr1" )
597597
598598 ctx := logutil .NewTestLoggerIntoContext (context .Background ())
599599 ds := datastore .NewDatastore (t .Context (), nil )
600600 mockSched := & mockScheduler {}
601- director := NewDirectorWithConfig (ds , mockSched , nil , NewConfig ().WithPostResponsePlugins (pr1 ))
601+ director := NewDirectorWithConfig (ds , mockSched , nil , NewConfig ().WithPostResponseRecievedPlugins (pr1 ))
602602
603603 reqCtx := & handlers.RequestContext {
604604 Request : & handlers.Request {
@@ -613,7 +613,7 @@ func TestDirector_HandleResponse(t *testing.T) {
613613 TargetPod : & backend.Pod {NamespacedName : types.NamespacedName {Namespace : "namespace1" , Name : "test-pod-name" }},
614614 }
615615
616- _ , err := director .HandleResponse (ctx , reqCtx )
616+ _ , err := director .HandleResponseRecieved (ctx , reqCtx )
617617 if err != nil {
618618 t .Fatalf ("HandleResponse() returned unexpected error: %v" , err )
619619 }
@@ -629,27 +629,143 @@ func TestDirector_HandleResponse(t *testing.T) {
629629 }
630630}
631631
632+ func TestDirector_HandleResponseStreaming (t * testing.T ) {
633+ ps1 := newTestPostResponseStreaming ("ps1" )
634+
635+ ctx := logutil .NewTestLoggerIntoContext (context .Background ())
636+ ds := datastore .NewDatastore (t .Context (), nil )
637+ mockSched := & mockScheduler {}
638+ director := NewDirectorWithConfig (ds , mockSched , nil , NewConfig ().WithPostResponseStreamingPlugins (ps1 ))
639+
640+ reqCtx := & handlers.RequestContext {
641+ Request : & handlers.Request {
642+ Headers : map [string ]string {
643+ requtil .RequestIdHeaderKey : "test-req-id-for-streaming" ,
644+ },
645+ },
646+ Response : & handlers.Response {
647+ Headers : map [string ]string {"X-Test-Streaming-Header" : "StreamValue" },
648+ },
649+ TargetPod : & backend.Pod {NamespacedName : types.NamespacedName {Namespace : "namespace1" , Name : "test-pod-name" }},
650+ }
651+
652+ _ , err := director .HandleResponseBodyStreaming (ctx , reqCtx )
653+ if err != nil {
654+ t .Fatalf ("HandleResponseBodyStreaming() returned unexpected error: %v" , err )
655+ }
656+
657+ if diff := cmp .Diff ("test-req-id-for-streaming" , ps1 .lastRespOnStreaming .RequestId ); diff != "" {
658+ t .Errorf ("Scheduler.OnStreaming RequestId mismatch (-want +got):\n %s" , diff )
659+ }
660+ if diff := cmp .Diff (reqCtx .Response .Headers , ps1 .lastRespOnStreaming .Headers ); diff != "" {
661+ t .Errorf ("Scheduler.OnStreaming Headers mismatch (-want +got):\n %s" , diff )
662+ }
663+ if diff := cmp .Diff ("namespace1/test-pod-name" , ps1 .lastTargetPodOnStreaming ); diff != "" {
664+ t .Errorf ("Scheduler.OnStreaming TargetPodName mismatch (-want +got):\n %s" , diff )
665+ }
666+ }
667+
668+ func TestDirector_HandleResponseComplete (t * testing.T ) {
669+ pc1 := newTestPostResponseComplete ("pc1" )
670+
671+ ctx := logutil .NewTestLoggerIntoContext (context .Background ())
672+ ds := datastore .NewDatastore (t .Context (), nil )
673+ mockSched := & mockScheduler {}
674+ director := NewDirectorWithConfig (ds , mockSched , nil , NewConfig ().WithPostResponseCompletePlugins (pc1 ))
675+
676+ reqCtx := & handlers.RequestContext {
677+ Request : & handlers.Request {
678+ Headers : map [string ]string {
679+ requtil .RequestIdHeaderKey : "test-req-id-for-complete" ,
680+ },
681+ },
682+ Response : & handlers.Response {
683+ Headers : map [string ]string {"X-Test-Complete-Header" : "CompleteValue" },
684+ },
685+ TargetPod : & backend.Pod {NamespacedName : types.NamespacedName {Namespace : "namespace1" , Name : "test-pod-name" }},
686+ }
687+
688+ _ , err := director .HandleResponseBodyComplete (ctx , reqCtx )
689+ if err != nil {
690+ t .Fatalf ("HandleResponseBodyComplete() returned unexpected error: %v" , err )
691+ }
692+
693+ if diff := cmp .Diff ("test-req-id-for-complete" , pc1 .lastRespOnComplete .RequestId ); diff != "" {
694+ t .Errorf ("Scheduler.OnComplete RequestId mismatch (-want +got):\n %s" , diff )
695+ }
696+ if diff := cmp .Diff (reqCtx .Response .Headers , pc1 .lastRespOnComplete .Headers ); diff != "" {
697+ t .Errorf ("Scheduler.OnComplete Headers mismatch (-want +got):\n %s" , diff )
698+ }
699+ if diff := cmp .Diff ("namespace1/test-pod-name" , pc1 .lastTargetPodOnComplete ); diff != "" {
700+ t .Errorf ("Scheduler.OnComplete TargetPodName mismatch (-want +got):\n %s" , diff )
701+ }
702+ }
703+
632704const (
633- testPostResponseType = "test-post-response"
705+ testPostResponseRecievedType = "test-post-response"
706+ testPostStreamingType = "test-post-streaming"
707+ testPostCompleteType = "test-post-complete"
634708)
635709
636- type testPostResponse struct {
710+ type testPostResponseRecieved struct {
637711 tn plugins.TypedName
638712 lastRespOnResponse * Response
639713 lastTargetPodOnResponse string
640714}
641715
642- func newTestPostResponse (name string ) * testPostResponse {
643- return & testPostResponse {
644- tn : plugins.TypedName {Type : testPostResponseType , Name : name },
716+ type testPostResponseStreaming struct {
717+ tn plugins.TypedName
718+ lastRespOnStreaming * Response
719+ lastTargetPodOnStreaming string
720+ }
721+
722+ type testPostResponseComplete struct {
723+ tn plugins.TypedName
724+ lastRespOnComplete * Response
725+ lastTargetPodOnComplete string
726+ }
727+
728+ func newTestPostResponseRecieved (name string ) * testPostResponseRecieved {
729+ return & testPostResponseRecieved {
730+ tn : plugins.TypedName {Type : testPostResponseRecievedType , Name : name },
645731 }
646732}
647733
648- func (p * testPostResponse ) TypedName () plugins.TypedName {
734+ func newTestPostResponseStreaming (name string ) * testPostResponseStreaming {
735+ return & testPostResponseStreaming {
736+ tn : plugins.TypedName {Type : testPostStreamingType , Name : name },
737+ }
738+ }
739+
740+ func newTestPostResponseComplete (name string ) * testPostResponseComplete {
741+ return & testPostResponseComplete {
742+ tn : plugins.TypedName {Type : testPostCompleteType , Name : name },
743+ }
744+ }
745+
746+ func (p * testPostResponseRecieved ) TypedName () plugins.TypedName {
747+ return p .tn
748+ }
749+
750+ func (p * testPostResponseStreaming ) TypedName () plugins.TypedName {
751+ return p .tn
752+ }
753+
754+ func (p * testPostResponseComplete ) TypedName () plugins.TypedName {
649755 return p .tn
650756}
651757
652- func (p * testPostResponse ) PostResponse (_ context.Context , _ * schedulingtypes.LLMRequest , response * Response , targetPod * backend.Pod ) {
758+ func (p * testPostResponseRecieved ) PostResponseRecieved (_ context.Context , _ * schedulingtypes.LLMRequest , response * Response , targetPod * backend.Pod ) {
653759 p .lastRespOnResponse = response
654760 p .lastTargetPodOnResponse = targetPod .NamespacedName .String ()
655761}
762+
763+ func (p * testPostResponseStreaming ) PostResponseStreaming (_ context.Context , _ * schedulingtypes.LLMRequest , response * Response , targetPod * backend.Pod ) {
764+ p .lastRespOnStreaming = response
765+ p .lastTargetPodOnStreaming = targetPod .NamespacedName .String ()
766+ }
767+
768+ func (p * testPostResponseComplete ) PostResponseComplete (_ context.Context , _ * schedulingtypes.LLMRequest , response * Response , targetPod * backend.Pod ) {
769+ p .lastRespOnComplete = response
770+ p .lastTargetPodOnComplete = targetPod .NamespacedName .String ()
771+ }
0 commit comments