|
8 | 8 |
|
9 | 9 | "github.com/stretchr/testify/assert" |
10 | 10 | "github.com/stretchr/testify/require" |
| 11 | + "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework" |
11 | 12 | "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types" |
12 | 13 |
|
13 | 14 | "github.com/llm-d/llm-d-inference-scheduler/pkg/common" |
@@ -120,6 +121,75 @@ func TestDataParallelProfileHandlerFactoryInvalidJSON(t *testing.T) { |
120 | 121 | } |
121 | 122 | } |
122 | 123 |
|
| 124 | +func Test_DataParallelProfileHandler_Pick(t *testing.T) { |
| 125 | + tests := []struct { |
| 126 | + name string |
| 127 | + profiles map[string]*framework.SchedulerProfile |
| 128 | + profileResults map[string]*types.ProfileRunResult |
| 129 | + expectEmptyResult bool |
| 130 | + expectLogError bool |
| 131 | + description string |
| 132 | + }{ |
| 133 | + { |
| 134 | + name: "success: single profile, first call", |
| 135 | + profiles: map[string]*framework.SchedulerProfile{ |
| 136 | + "default": {}, |
| 137 | + }, |
| 138 | + profileResults: map[string]*types.ProfileRunResult{}, |
| 139 | + expectEmptyResult: false, |
| 140 | + expectLogError: false, |
| 141 | + description: "Should return the single profile to run", |
| 142 | + }, |
| 143 | + { |
| 144 | + name: "success: single profile, second call (all already executed)", |
| 145 | + profiles: map[string]*framework.SchedulerProfile{ |
| 146 | + "default": {}, |
| 147 | + }, |
| 148 | + profileResults: map[string]*types.ProfileRunResult{ |
| 149 | + "default": newMockProfileRunResult(DefaultTestPodPort, "pod1"), |
| 150 | + }, |
| 151 | + expectEmptyResult: true, |
| 152 | + expectLogError: false, |
| 153 | + description: "Should return empty map since all profiles have been executed already in previous call", |
| 154 | + }, |
| 155 | + { |
| 156 | + name: "error: multiple profiles configured in EPP", |
| 157 | + profiles: map[string]*framework.SchedulerProfile{ |
| 158 | + "profile1": {}, |
| 159 | + "profile2": {}, |
| 160 | + }, |
| 161 | + profileResults: map[string]*types.ProfileRunResult{}, |
| 162 | + expectEmptyResult: true, |
| 163 | + expectLogError: true, |
| 164 | + description: "Should return empty map and log error for multiple profiles", |
| 165 | + }, |
| 166 | + { |
| 167 | + name: "error: zero profiles configured in EPP", |
| 168 | + profiles: map[string]*framework.SchedulerProfile{}, |
| 169 | + profileResults: map[string]*types.ProfileRunResult{}, |
| 170 | + expectEmptyResult: true, |
| 171 | + expectLogError: true, |
| 172 | + description: "Should return empty map and log error for zero profiles", |
| 173 | + }, |
| 174 | + } |
| 175 | + |
| 176 | + for _, tt := range tests { |
| 177 | + t.Run(tt.name, func(t *testing.T) { |
| 178 | + handler := NewDataParallelProfileHandler(8000).WithName("test-handler") |
| 179 | + ctx := context.Background() |
| 180 | + |
| 181 | + result := handler.Pick(ctx, &types.CycleState{}, &types.LLMRequest{}, tt.profiles, tt.profileResults) |
| 182 | + |
| 183 | + if tt.expectEmptyResult { |
| 184 | + assert.Empty(t, result, tt.description) |
| 185 | + } else { |
| 186 | + assert.NotEmpty(t, result, tt.description) |
| 187 | + assert.Equal(t, len(tt.profiles), len(result), "Should return all profiles when valid") |
| 188 | + } |
| 189 | + }) |
| 190 | + } |
| 191 | +} |
| 192 | + |
123 | 193 | func Test_DataParallelProfileHandler_ProcessResults(t *testing.T) { |
124 | 194 | tests := []struct { |
125 | 195 | name string |
|
0 commit comments