Skip to content
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

Rename NewGoRoutine to Run in GoRoutineMap #25597

Merged
merged 1 commit into from
May 14, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions pkg/util/goroutinemap/goroutinemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ import (

// GoRoutineMap defines the supported set of operations.
type GoRoutineMap interface {
Copy link
Member

Choose a reason for hiding this comment

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

while you're at it, this should be GoroutineMap. "Goroutine" is a noun.

// NewGoRoutine adds operationName to the list of running operations and
// spawns a new go routine to execute the operation. If an operation with
// the same name already exists, an error is returned. Once the operation
// is complete, the go routine is terminated and the operationName is
// removed from the list of executing operations allowing a new operation
// to be started with the same name without error.
NewGoRoutine(operationName string, operation func() error) error
// Run adds operationName to the list of running operations and spawns a new
// go routine to execute the operation. If an operation with the same name
// already exists, an error is returned. Once the operation is complete, the
// go routine is terminated and the operationName is removed from the list
// of executing operations allowing a new operation to be started with the
// same name without error.
Run(operationName string, operation func() error) error

// Wait blocks until all operations are completed. This is typically
// necessary during tests - the test should wait until all operations finish
Expand All @@ -57,7 +57,7 @@ type goRoutineMap struct {
wg sync.WaitGroup
}

func (grm *goRoutineMap) NewGoRoutine(operationName string, operation func() error) error {
func (grm *goRoutineMap) Run(operationName string, operation func() error) error {
grm.Lock()
defer grm.Unlock()
if grm.operations[operationName] {
Expand Down
22 changes: 11 additions & 11 deletions pkg/util/goroutinemap/goroutinemap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Test_NewGoRoutineMap_Positive_SingleOp(t *testing.T) {
operation := func() error { return nil }

// Act
err := grm.NewGoRoutine(operationName, operation)
err := grm.Run(operationName, operation)

// Assert
if err != nil {
Expand All @@ -45,7 +45,7 @@ func Test_NewGoRoutineMap_Positive_SecondOpAfterFirstCompletes(t *testing.T) {
operationName := "operation-name"
operation1DoneCh := make(chan interface{}, 0 /* bufferSize */)
operation1 := generateCallbackFunc(operation1DoneCh)
err1 := grm.NewGoRoutine(operationName, operation1)
err1 := grm.Run(operationName, operation1)
if err1 != nil {
t.Fatalf("NewGoRoutine failed. Expected: <no error> Actual: <%v>", err1)
}
Expand All @@ -56,7 +56,7 @@ func Test_NewGoRoutineMap_Positive_SecondOpAfterFirstCompletes(t *testing.T) {
err2 := retryWithExponentialBackOff(
time.Duration(20*time.Millisecond),
func() (bool, error) {
err := grm.NewGoRoutine(operationName, operation2)
err := grm.Run(operationName, operation2)
if err != nil {
t.Logf("Warning: NewGoRoutine failed. Expected: <no error> Actual: <%v>. Will retry.", err)
return false, nil
Expand All @@ -76,7 +76,7 @@ func Test_NewGoRoutineMap_Positive_SecondOpAfterFirstPanics(t *testing.T) {
grm := NewGoRoutineMap()
operationName := "operation-name"
operation1 := generatePanicFunc()
err1 := grm.NewGoRoutine(operationName, operation1)
err1 := grm.Run(operationName, operation1)
if err1 != nil {
t.Fatalf("NewGoRoutine failed. Expected: <no error> Actual: <%v>", err1)
}
Expand All @@ -86,7 +86,7 @@ func Test_NewGoRoutineMap_Positive_SecondOpAfterFirstPanics(t *testing.T) {
err2 := retryWithExponentialBackOff(
time.Duration(20*time.Millisecond),
func() (bool, error) {
err := grm.NewGoRoutine(operationName, operation2)
err := grm.Run(operationName, operation2)
if err != nil {
t.Logf("Warning: NewGoRoutine failed. Expected: <no error> Actual: <%v>. Will retry.", err)
return false, nil
Expand All @@ -107,14 +107,14 @@ func Test_NewGoRoutineMap_Negative_SecondOpBeforeFirstCompletes(t *testing.T) {
operationName := "operation-name"
operation1DoneCh := make(chan interface{}, 0 /* bufferSize */)
operation1 := generateWaitFunc(operation1DoneCh)
err1 := grm.NewGoRoutine(operationName, operation1)
err1 := grm.Run(operationName, operation1)
if err1 != nil {
t.Fatalf("NewGoRoutine failed. Expected: <no error> Actual: <%v>", err1)
}
operation2 := generateNoopFunc()

// Act
err2 := grm.NewGoRoutine(operationName, operation2)
err2 := grm.Run(operationName, operation2)

// Assert
if err2 == nil {
Expand All @@ -128,15 +128,15 @@ func Test_NewGoRoutineMap_Positive_ThirdOpAfterFirstCompletes(t *testing.T) {
operationName := "operation-name"
operation1DoneCh := make(chan interface{}, 0 /* bufferSize */)
operation1 := generateWaitFunc(operation1DoneCh)
err1 := grm.NewGoRoutine(operationName, operation1)
err1 := grm.Run(operationName, operation1)
if err1 != nil {
t.Fatalf("NewGoRoutine failed. Expected: <no error> Actual: <%v>", err1)
}
operation2 := generateNoopFunc()
operation3 := generateNoopFunc()

// Act
err2 := grm.NewGoRoutine(operationName, operation2)
err2 := grm.Run(operationName, operation2)

// Assert
if err2 == nil {
Expand All @@ -148,7 +148,7 @@ func Test_NewGoRoutineMap_Positive_ThirdOpAfterFirstCompletes(t *testing.T) {
err3 := retryWithExponentialBackOff(
time.Duration(20*time.Millisecond),
func() (bool, error) {
err := grm.NewGoRoutine(operationName, operation3)
err := grm.Run(operationName, operation3)
if err != nil {
t.Logf("Warning: NewGoRoutine failed. Expected: <no error> Actual: <%v>. Will retry.", err)
return false, nil
Expand Down Expand Up @@ -224,7 +224,7 @@ func Test_NewGoRoutineMap_Positive_Wait(t *testing.T) {
operationName := "operation-name"
operation1DoneCh := make(chan interface{}, 0 /* bufferSize */)
operation1 := generateWaitFunc(operation1DoneCh)
err := grm.NewGoRoutine(operationName, operation1)
err := grm.Run(operationName, operation1)
if err != nil {
t.Fatalf("NewGoRoutine failed. Expected: <no error> Actual: <%v>", err)
}
Expand Down