Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugin/gthulhu/gthulhu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ func (m *MockScheduler) DefaultSelectCPU(t *models.QueuedTask) (error, int32) {
return nil, cpu
}

func (m *MockScheduler) GetNrQueued() uint64 {
Copy link

Copilot AI Jan 30, 2026

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)

Suggested change
func (m *MockScheduler) GetNrQueued() uint64 {
func (m *MockScheduler) GetNrQueued() uint64 {
if m.queueIndex >= len(m.taskQueue) {
return 0
}

Copilot uses AI. Check for mistakes.
return uint64(len(m.taskQueue) - m.queueIndex)
}

// Reset resets the mock scheduler state
func (m *MockScheduler) Reset() {
m.taskQueue = make([]*models.QueuedTask, 0)
Expand Down
1 change: 1 addition & 0 deletions plugin/internal/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type Sched interface {
DequeueTask(task *models.QueuedTask)
DefaultSelectCPU(t *models.QueuedTask) (error, int32)
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new GetNrQueued method lacks documentation. Consider adding a comment explaining its purpose and expected behavior, similar to how other interface methods are documented. For example: "GetNrQueued returns the number of tasks currently queued and waiting to be dequeued."

Suggested change
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.

Copilot uses AI. Check for mistakes.
GetNrQueued() uint64
}

type CustomScheduler interface {
Expand Down
4 changes: 4 additions & 0 deletions plugin/simple/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ func (m *MockScheduler) DefaultSelectCPU(t *models.QueuedTask) (error, int32) {
return nil, cpu
}

func (m *MockScheduler) GetNrQueued() uint64 {
Copy link

Copilot AI Jan 30, 2026

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)

Suggested change
func (m *MockScheduler) GetNrQueued() uint64 {
func (m *MockScheduler) GetNrQueued() uint64 {
if m.queueIndex >= len(m.taskQueue) {
return 0
}

Copilot uses AI. Check for mistakes.
return uint64(len(m.taskQueue) - m.queueIndex)
}
Comment on lines +166 to +168
Copy link

Copilot AI Jan 30, 2026

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.

Copilot uses AI. Check for mistakes.

// Reset resets the mock scheduler state
func (m *MockScheduler) Reset() {
m.taskQueue = make([]*models.QueuedTask, 0)
Expand Down
7 changes: 6 additions & 1 deletion tests/factory_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand Down Expand Up @@ -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 {
Copy link

Copilot AI Jan 30, 2026

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 index somehow becomes greater than len(s.tasks), 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 s.index > len(s.tasks) { return 0 } before the calculation, or use: if s.index >= len(s.tasks) { return 0 } return uint64(len(s.tasks) - s.index)

Suggested change
func (s *testSched) GetNrQueued() uint64 {
func (s *testSched) GetNrQueued() uint64 {
if s.index >= len(s.tasks) {
return 0
}

Copilot uses AI. Check for mistakes.
return uint64(len(s.tasks) - s.index)
}
Loading