MCPcopy Create free account
hub / github.com/flant/shell-operator / TestTaskStorage_EdgeCases

Function TestTaskStorage_EdgeCases

pkg/task/queue/task_storage_test.go:529–583  ·  view source on GitHub ↗

TestTaskStorage_EdgeCases tests various edge cases

(t *testing.T)

Source from the content-addressed store, hash-verified

527
528// TestTaskStorage_EdgeCases tests various edge cases
529func TestTaskStorage_EdgeCases(t *testing.T) {
530 ts := newTaskStorage()
531
532 // Test operations on empty storage
533 if ts.RemoveFirst() != nil {
534 t.Error("RemoveFirst on empty storage should return nil")
535 }
536
537 if ts.RemoveLast() != nil {
538 t.Error("RemoveLast on empty storage should return nil")
539 }
540
541 if ts.Remove("nonexistent") != nil {
542 t.Error("Remove nonexistent ID should return nil")
543 }
544
545 // Test AddAfter/AddBefore with empty storage
546 ts.AddAfter("nonexistent", task.NewTask("test"))
547 ts.AddBefore("nonexistent", task.NewTask("test"))
548
549 if ts.Length() != 0 {
550 t.Error("Adding after/before nonexistent IDs in empty storage should not add tasks")
551 }
552
553 // Test with single task
554 singleTask := task.NewTask("single")
555 ts.AddLast(singleTask)
556
557 if ts.GetFirst() != singleTask {
558 t.Error("Single task should be both first and last")
559 }
560
561 if ts.GetLast() != singleTask {
562 t.Error("Single task should be both first and last")
563 }
564
565 // Remove the single task
566 if ts.RemoveFirst() != singleTask {
567 t.Error("RemoveFirst should return the single task")
568 }
569
570 if ts.Length() != 0 {
571 t.Error("Storage should be empty after removing single task")
572 }
573
574 // Test ProcessResult with non-existent task
575 result := &TaskResult{Status: Success}
576 result.AddHeadTasks(task.NewTask("head"))
577 ts.ProcessResult(*result, task.NewTask("nonexistent"))
578
579 // Should still add head tasks even if target task doesn't exist
580 if ts.Length() != 1 {
581 t.Errorf("Expected 1 task after ProcessResult with non-existent task, got %d", ts.Length())
582 }
583}
584
585// TestTaskStorage_LargeScaleOperations tests performance and correctness with many operations
586func TestTaskStorage_LargeScaleOperations(t *testing.T) {

Callers

nothing calls this directly

Calls 14

AddHeadTasksMethod · 0.95
NewTaskFunction · 0.92
newTaskStorageFunction · 0.85
ProcessResultMethod · 0.80
RemoveFirstMethod · 0.65
RemoveMethod · 0.65
AddLastMethod · 0.65
GetFirstMethod · 0.65
ErrorMethod · 0.45
RemoveLastMethod · 0.45
AddAfterMethod · 0.45
AddBeforeMethod · 0.45

Tested by

no test coverage detected