@@ -38,48 +38,48 @@ func newPlugin(t *testing.T, mode string) *gpuJobOrderPlugin {
3838 return rp
3939}
4040
41- func TestJobOrderFn_PriorityDiffers_Defers (t * testing.T ) {
41+ func TestVictimOrderFn_PriorityDiffers_Defers (t * testing.T ) {
4242 vm := resource_info .NewResourceVectorMap ()
4343 a := makeGPUPodGroup ("a" , 50 , 1 , vm )
4444 b := makeGPUPodGroup ("b" , 10 , 1 , vm )
4545 rp := newPlugin (t , "" )
46- if got := rp .JobOrderFn (a , b ); got != 0 {
46+ if got := rp .VictimOrderFn (a , b ); got != 0 {
4747 t .Errorf ("expected 0 when priorities differ, got %d" , got )
4848 }
4949}
5050
51- func TestJobOrderFn_SamePriority_PrefersLarger_Default (t * testing.T ) {
51+ func TestVictimOrderFn_SamePriority_PrefersLarger_Default (t * testing.T ) {
5252 vm := resource_info .NewResourceVectorMap ()
5353 small := makeGPUPodGroup ("small" , 10 , 1 , vm )
5454 large := makeGPUPodGroup ("large" , 10 , 2 , vm )
5555 rp := newPlugin (t , "" )
56- if got := rp .JobOrderFn (large , small ); got != - 1 {
56+ if got := rp .VictimOrderFn (large , small ); got != - 1 {
5757 t .Errorf ("expected -1 (larger job preferred as victim), got %d" , got )
5858 }
59- if got := rp .JobOrderFn (small , large ); got != 1 {
59+ if got := rp .VictimOrderFn (small , large ); got != 1 {
6060 t .Errorf ("expected 1, got %d" , got )
6161 }
6262}
6363
64- func TestJobOrderFn_SamePriority_SameGPU_FallsThrough (t * testing.T ) {
64+ func TestVictimOrderFn_SamePriority_SameGPU_FallsThrough (t * testing.T ) {
6565 vm := resource_info .NewResourceVectorMap ()
6666 a := makeGPUPodGroup ("a" , 10 , 1 , vm )
6767 b := makeGPUPodGroup ("b" , 10 , 1 , vm )
6868 rp := newPlugin (t , "" )
69- if got := rp .JobOrderFn (a , b ); got != 0 {
69+ if got := rp .VictimOrderFn (a , b ); got != 0 {
7070 t .Errorf ("expected 0 (equal GPU falls through), got %d" , got )
7171 }
7272}
7373
74- func TestJobOrderFn_PreferSmallerMode (t * testing.T ) {
74+ func TestVictimOrderFn_PreferSmallerMode (t * testing.T ) {
7575 vm := resource_info .NewResourceVectorMap ()
7676 small := makeGPUPodGroup ("small" , 10 , 1 , vm )
7777 large := makeGPUPodGroup ("large" , 10 , 2 , vm )
7878 rp := newPlugin (t , "prefer-smaller" )
79- if got := rp .JobOrderFn (small , large ); got != - 1 {
79+ if got := rp .VictimOrderFn (small , large ); got != - 1 {
8080 t .Errorf ("expected -1 (smaller job preferred as victim in prefer-smaller mode), got %d" , got )
8181 }
82- if got := rp .JobOrderFn (large , small ); got != 1 {
82+ if got := rp .VictimOrderFn (large , small ); got != 1 {
8383 t .Errorf ("expected 1, got %d" , got )
8484 }
8585}
@@ -89,7 +89,44 @@ func TestNew_UnrecognizedMode_FallsBackToPreferLarger(t *testing.T) {
8989 small := makeGPUPodGroup ("small" , 10 , 1 , vm )
9090 large := makeGPUPodGroup ("large" , 10 , 2 , vm )
9191 rp := newPlugin (t , "totally-not-a-real-mode" )
92- if got := rp .JobOrderFn (large , small ); got != - 1 {
92+ if got := rp .VictimOrderFn (large , small ); got != - 1 {
9393 t .Errorf ("expected fallback to prefer-larger behavior, got %d" , got )
9494 }
9595}
96+
97+ // TestGpujoborder_DoesNotAffect_PendingJobOrdering is the specific test
98+ // gshaibi asked for: confirms that registering gpujoborder's comparator
99+ // has NO EFFECT on ssn.JobOrderFn (pending-job allocation ordering),
100+ // since the plugin now registers exclusively via AddVictimOrderFn.
101+ func TestGpujoborder_DoesNotAffect_PendingJobOrdering (t * testing.T ) {
102+ rp := newPlugin (t , "" )
103+
104+ vm := resource_info .NewResourceVectorMap ()
105+ small := makeGPUPodGroup ("small" , 10 , 1 , vm )
106+ large := makeGPUPodGroup ("large" , 10 , 2 , vm )
107+
108+ // Session WITHOUT gpujoborder registered: falls through to the
109+ // existing CreationTimestamp/UID fallback for JobOrderFn.
110+ ssnWithout := & framework.Session {}
111+ baselineResult := ssnWithout .JobOrderFn (small , large )
112+
113+ // Session WITH gpujoborder registered via OnSessionOpen (the real
114+ // registration path), same two jobs, same JobOrderFn call.
115+ ssnWith := & framework.Session {}
116+ rp .OnSessionOpen (ssnWith )
117+ withPluginResult := ssnWith .JobOrderFn (small , large )
118+
119+ if len (ssnWith .JobOrderFns ) != 0 {
120+ t .Errorf ("expected gpujoborder to register 0 JobOrderFns (it should only " +
121+ "register via AddVictimOrderFn now), got %d" , len (ssnWith .JobOrderFns ))
122+ }
123+ if len (ssnWith .VictimOrderFns ) != 1 {
124+ t .Errorf ("expected gpujoborder to register exactly 1 VictimOrderFn, got %d" ,
125+ len (ssnWith .VictimOrderFns ))
126+ }
127+ if baselineResult != withPluginResult {
128+ t .Errorf ("pending-job ordering changed after registering gpujoborder: " +
129+ "without=%v, with=%v -- expected identical, since gpujoborder must not " +
130+ "affect JobOrderFn at all" , baselineResult , withPluginResult )
131+ }
132+ }
0 commit comments