package syncengine import ( "testing" ) func TestQueue(t *testing.T) { q := NewQueue() if q.IsRunning(100) { t.Error("queue should be empty") } cancelCalled := false cancel := func() { cancelCalled = true } err := q.Enqueue(1, 100, cancel) if err != nil { t.Errorf("Enqueue(1, 100) unexpected error: %v", err) } if !q.IsRunning(100) { t.Error("queue should contain job 100") } jobID, ok := q.GetByPair(1) if !ok || jobID != 100 { t.Errorf("GetByPair(1) = %d, %v, want 100, true", jobID, ok) } err = q.Enqueue(1, 200, nil) if err != ErrAlreadyRunning { t.Errorf("Enqueue(1, 200) = %v, want ErrAlreadyRunning", err) } ok = q.Cancel(100, true) if !ok { t.Error("Cancel(100) should return true") } if !cancelCalled { t.Error("Cancel should have called the cancel func") } if !q.IsCancelledByUser(100) { t.Error("IsCancelledByUser should return true after Cancel(100, true)") } q.Dequeue(100) if q.IsRunning(100) { t.Error("queue should be empty after Dequeue") } }