Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
f7196337
Commit
f7196337
authored
May 13, 2016
by
saadali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename NewGoRoutine to Run in GoRoutineMap
parent
24c46acd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
19 deletions
+19
-19
goroutinemap.go
pkg/util/goroutinemap/goroutinemap.go
+8
-8
goroutinemap_test.go
pkg/util/goroutinemap/goroutinemap_test.go
+11
-11
No files found.
pkg/util/goroutinemap/goroutinemap.go
View file @
f7196337
...
...
@@ -30,13 +30,13 @@ import (
// GoRoutineMap defines the supported set of operations.
type
GoRoutineMap
interface
{
//
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
...
...
@@ -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
]
{
...
...
pkg/util/goroutinemap/goroutinemap_test.go
View file @
f7196337
...
...
@@ -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
{
...
...
@@ -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
)
}
...
...
@@ -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
...
...
@@ -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
)
}
...
...
@@ -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
...
...
@@ -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
{
...
...
@@ -128,7 +128,7 @@ 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
)
}
...
...
@@ -136,7 +136,7 @@ func Test_NewGoRoutineMap_Positive_ThirdOpAfterFirstCompletes(t *testing.T) {
operation3
:=
generateNoopFunc
()
// Act
err2
:=
grm
.
NewGoRoutine
(
operationName
,
operation2
)
err2
:=
grm
.
Run
(
operationName
,
operation2
)
// Assert
if
err2
==
nil
{
...
...
@@ -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
...
...
@@ -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
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment