-
Notifications
You must be signed in to change notification settings - Fork 1
feat: added GetNrQueued API #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,7 @@ import ( | |||||||
| type Sched interface { | ||||||||
| DequeueTask(task *models.QueuedTask) | ||||||||
| DefaultSelectCPU(t *models.QueuedTask) (error, int32) | ||||||||
|
||||||||
| DefaultSelectCPU(t *models.QueuedTask) (error, int32) | |
| DefaultSelectCPU(t *models.QueuedTask) (error, int32) | |
| // GetNrQueued returns the number of tasks currently queued and waiting to be dequeued. |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -163,6 +163,10 @@ func (m *MockScheduler) DefaultSelectCPU(t *models.QueuedTask) (error, int32) { | |||||||||||
| return nil, cpu | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| func (m *MockScheduler) GetNrQueued() uint64 { | ||||||||||||
|
||||||||||||
| func (m *MockScheduler) GetNrQueued() uint64 { | |
| func (m *MockScheduler) GetNrQueued() uint64 { | |
| if m.queueIndex >= len(m.taskQueue) { | |
| return 0 | |
| } |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The newly added GetNrQueued method is not called or tested anywhere in the codebase. Consider adding unit tests that verify the method returns correct values in various scenarios (e.g., empty queue, partially dequeued queue, fully dequeued queue) to ensure the implementation works as expected.
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -354,7 +354,8 @@ func TestMultiplePluginInstances(t *testing.T) { | |||||||||||
| PublicKeyPath: "/path/to/key", | ||||||||||||
| BaseURL: "https://api.example.com", | ||||||||||||
| Interval: 10, | ||||||||||||
| }} | ||||||||||||
| }, | ||||||||||||
| } | ||||||||||||
| simpleConfig := &plugin.SchedConfig{Mode: "simple"} | ||||||||||||
| fifoConfig := &plugin.SchedConfig{Mode: "simple-fifo"} | ||||||||||||
|
|
||||||||||||
|
|
@@ -432,3 +433,7 @@ func (s *testSched) DequeueTask(task *models.QueuedTask) { | |||||||||||
| func (s *testSched) DefaultSelectCPU(t *models.QueuedTask) (error, int32) { | ||||||||||||
| return nil, 0 | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| func (s *testSched) GetNrQueued() uint64 { | ||||||||||||
|
||||||||||||
| func (s *testSched) GetNrQueued() uint64 { | |
| func (s *testSched) GetNrQueued() uint64 { | |
| if s.index >= len(s.tasks) { | |
| return 0 | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GetNrQueued implementation has a potential integer underflow issue. If queueIndex somehow becomes greater than len(m.taskQueue), the subtraction would produce a negative value which, when cast to uint64, would wrap around to a very large positive number. Consider adding a safety check: if m.queueIndex > len(m.taskQueue) { return 0 } before the calculation, or use: if m.queueIndex >= len(m.taskQueue) { return 0 } return uint64(len(m.taskQueue) - m.queueIndex)